首页 > 解决方案 > 初始化没有标头的数据帧

问题描述

要创建带有标题的熊猫数据框,我可以这样做:

df = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6]})

   a  b
0  1  4
1  2  5
2  3  6

我将如何创建一个没有标题,例如:

df = pd.DataFrame([[1,2,3],[4,5,6]])

   0  1  2
0  1  2  3
1  4  5  6
# seems to create three headers, '0', '1', and '2' for the index of the array.

标签: pythonpandas

解决方案


用于zip将列表解释为列而不是行(如果这是您的问题):

df = pd.DataFrame([*zip([1,2,3],[4,5,6])])
df
>>    0  1
0  1  4
1  2  5
2  3  6

推荐阅读