蟒蛇创建一个数据框与列表的一行 [英] python create a data frame with one row by a list
本文介绍了蟒蛇创建一个数据框与列表的一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在python中,说我有一个列表[1,2,3,...,100],我想使用此列表来创建一个数据帧,该数据帧具有一行并且行值为该列表.最快,最优雅的方法是什么?
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?
推荐答案
将列表作为列表参数传递给data
:
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]
您可以将列名称作为arg传递给DataFrame
构造函数或直接分配:
You can pass the columns names as an arg to the DataFrame
constructor or assign directly:
pd.DataFrame(data=[l], columns = col_list)
或
df.columns = col_list
这篇关于蟒蛇创建一个数据框与列表的一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文