Python creates a single-row data frame in a list

in python, let's say I have a list [1,2,3, ..., 100], and I would like to use this list to create a data frame that has one row and the value of the row is a list. What is the fastest and most elegant way to do this?

+6
source share
1 answer

pass the list as a parameter to the data list:

 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 column names as arguments to the DataFrame constructor or assign them directly:

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

or

 df.columns = col_list 
+10
source

Source: https://habr.com/ru/post/983873/


All Articles