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

前端 未结 5 1241
旧时难觅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:42

    Strictly speaking if you want nested lists (and not a list of tuples) you can do

    df.values.tolist()
    

    as df.values is a numpy array. That will give you a list of lists as requested:

    [[0.0001313652121930252, 3.5915356549999985e-05], 
     [3.5915356549999985e-05, 0.00011634321240684215]]
    

提交回复
热议问题