简体   繁体   English

如何使用python将3D数组导出到excel中的单行

[英]How to export 3D array into a single row in excel using python

I am attempting to export a large array of 3D points into excel.我正在尝试将大量 3D 点导出到 excel 中。

import numpy as np
import pandas as pd

d = np.asarray(data)
df = pd.Dataframe(d)
df.to_csv("C:/Users/Fred/Desktop/test.csv")

This exports the data into rows as below:这会将数据导出到如下行中:

3.361490011 -27.39559937 -2.934410095
4.573401244 -26.45699201 -3.845634521

..... ......

Each line representing the x,y,z coordinates.每条线代表 x,y,z 坐标。 However, for my analysis, I would like that the 2nd row is moved to columns beside the 1st row, and so on, so that all the coordinates for one shape are on the one row of the excel.但是,对于我的分析,我希望将第二行移动到第一行旁边的列,依此类推,这样一个形状的所有坐标都在 excel 的一行上。 I tried turning the data into a string but this returned the above too.我尝试将数据转换为字符串,但这也返回了上述内容。

The reason is so I can add some population characteristics to the row for each 3d shape.原因是我可以为每个 3d 形状的行添加一些人口特征。 Thanks for any help that anyone can give.感谢任何人都可以提供的任何帮助。

您可以使用x = df.to_numpy().flatten()来展平数据,然后使用np.savetxt将其保存到 csv 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM