Convert list into a pandas data frame

前端 未结 1 1846
北荒
北荒 2020-12-03 01:14

I am trying to convert my output into a pandas data frame and I am struggling. I have this list

my_list = [1,2,3,4,5,6,7,8,9]

I want to cre

相关标签:
1条回答
  • 2020-12-03 01:54

    You need convert list to numpy array and then reshape:

    df = pd.DataFrame(np.array(my_list).reshape(3,3), columns = list("abc"))
    print (df)
       a  b  c
    0  1  2  3
    1  4  5  6
    2  7  8  9
    
    0 讨论(0)
提交回复
热议问题