python - 初始化没有标头的数据帧
问题描述
要创建带有标题的熊猫数据框,我可以这样做:
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.
解决方案
用于zip
将列表解释为列而不是行(如果这是您的问题):
df = pd.DataFrame([*zip([1,2,3],[4,5,6])])
df
>> 0 1
0 1 4
1 2 5
2 3 6
推荐阅读
- applescript - 使用 Applescript 更改文件在桌面上的排序方式
- apache - 如何在 WHM 中禁用“/controlpanel”目录重定向到:2083?
- node.js - 在 Express 和 Mongoose 中更新博客应用程序时遇到问题
- vue.js - 原生应用程序是否可以访问 HTML5 API
- apache-spark - Spark 2.4.0 - 不同的内存管理选项
- python - 如何循环我的定义?〜sum values直到达到限制并再次循环其余部分
- c# - C# - 如何在不指定泛型类型的情况下在“泛型类”类型的 MainForm 类中声明一个变量
- c# - 如何在 C# 中使用变量设置元素的高度?
- c# - .net 观察者模式变体(IObservable 和事件委托)之间有什么区别以及何时使用它们?
- python - TypeError:预期的序列或类似数组,得到估计器 KNeighborsClassifier