python create a data frame with one row by a list

前端 未结 1 604
萌比男神i
萌比男神i 2021-02-19 07:02

in python, say I have a list [1,2,3,...,100], and I would like to use this list to create a dataframe which has one row and the row value is the list. What is the fastest and el

1条回答
  •  面向向阳花
    2021-02-19 07:30

    pass the list as a list param to data:

    In [11]:
    
    l = range(1,100)
    pd.DataFrame(data=[l])
    Out[11]:
       0   1   2   3   4   5   6   7   8   9  ...  89  90  91  92  93  94  95  96  \
    0   1   2   3   4   5   6   7   8   9  10 ...  90  91  92  93  94  95  96  97   
    
       97  98  
    0  98  99  
    
    [1 rows x 99 columns]
    

    You can pass the columns names as an arg to the DataFrame constructor or assign directly:

    pd.DataFrame(data=[l], columns = col_list)

    or

    df.columns = col_list
    

    0 讨论(0)
提交回复
热议问题