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 elegant way to do this?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With