How to generate a list from a pandas DataFrame with the column name and column values?

前端 未结 5 1322
旧时难觅i
旧时难觅i 2021-02-02 14:00

I have a pandas dataframe object that looks like this:

   one  two  three  four  five
0    1    2      3     4     5
1    1    1      1     1     1
5条回答
  •  逝去的感伤
    2021-02-02 14:35

    @BrenBarn answer above yields a list of tuples not a list of list as asked in question. I specifically needed a list of lists to be able to write the dataframe into spreadsheed using DataNitro. Adapted the above example with list comprehension:

    [list(x) for x in dt.T.itertuples()]
    

    This yields the result as needed

提交回复
热议问题