[Python] Convert spark DataFrame column to python list

Discussão em 'Python' iniciado por Stack, Novembro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I work on a dataframe with two column, mvv and count.

    +---+-----+
    |mvv|count|
    +---+-----+
    | 1 | 5 |
    | 2 | 9 |
    | 3 | 3 |
    | 4 | 1 |


    i would like to obtain two list containing mvv values and count value. Something like

    mvv = [1,2,3,4]
    count = [5,9,3,1]


    So, I tried the following code: The first line should return a python list of row. I wanted to see the first value:

    mvv_list = mvv_count_df.select('mvv').collect()
    firstvalue = mvv_list[0].getInt(0)


    But I get an error message with the second line:


    AttributeError: getInt
    ​

    Continue reading...

Compartilhe esta Página