Python: create a pandas data frame from a list

前端 未结 3 1979
心在旅途
心在旅途 2020-12-05 13:05

I am using the following code to create a data frame from a list:

test_list = [\'a\',\'b\',\'c\',\'d\']
df_test = pd.DataFrame.from_records(test_list, column         


        
3条回答
  •  情歌与酒
    2020-12-05 13:35

    In[20]: test_list = [['a','b','c'], ['AA','BB','CC']]
    
    In[21]: pd.DataFrame(test_list, columns=['col_A', 'col_B', 'col_C'])
    Out[21]: 
      col_A col_B col_C
    0     a     b     c
    1    AA    BB    CC
    
    In[22]: pd.DataFrame(test_list, index=['col_low', 'col_up']).T
    Out[22]: 
      col_low col_up
    0       a     AA
    1       b     BB
    2       c     CC
    

提交回复
热议问题