python - 使用 col 名称创建的 Pandas 数据框
问题描述
美好的一天,我正在和熊猫一起工作。我有.xyz
数据。想从中创建熊猫。
point_cloud = pd.read_csv("Turning.xyz", delimiter=" ")
point_cloud = point_cloud.iloc[:,1:]
print(point_cloud.values[:5])
我用这种方式阅读。它起作用了,下面是输出。
[[ 5.29851664 2.17091972 -1.5342793 ]
[ 5.33154001 2.09907462 -1.53531458]
[ 5.33154001 2.09907462 -1.53531458]
[ 5.36755701 2.02716027 -1.53738513]
[ 5.37840056 2.03125554 -1.54049096]]
现在我希望数据框中的 1 col 是“X”,下一个是“Y”,下一个是“Z”。所以我这样做了:
point_cloud = pd.DataFrame(point_cloud.values[:5000], columns={"X","Y","Z"})
我的案子只拿了5000,因为里面有很多点。但是,它没有创建具有正常顺序 XYZ 的数据集,而是使用 YZX 创建的:
Y Z X
0 5.298517 2.170920 -1.534279
1 5.331540 2.099075 -1.535315
2 5.331540 2.099075 -1.535315
3 5.367557 2.027160 -1.537385
4 5.378401 2.031256 -1.540491
这是我第一次看到类似的东西。可能是什么原因以及如何解决?
解决方案
不要使用 aset
因为它是无序的集合。
代替:
columns={"X","Y","Z"}
经过:
columns=["X","Y","Z"]
推荐阅读
- ios - 自动更正更改文本时 UITextField 没有回调
- angular - Angular 8 - 材料表在删除时不显示正确的数据
- java - Axon FrameWork:如何在 domain_event_entry 表中回滚
- javascript - 为什么新的 expo init 会产生“导出默认函数”而不是“导出默认类”?在 App.js 中
- qt - 如何从文本中查找特定变量并在 qt 中的 qlineedit 上显示?
- sql - 根据第一个表填充第二个表
- android - 两个子模块之间的通信
- python - Python:从函数返回数组值
- android - 如何在 gradle 任务中检索库版本
- vb.net - 使用外键从绑定源中删除行