Home > other >  How to export 3D array into a single row in excel using python
How to export 3D array into a single row in excel using python

Time:06-30

I am attempting to export a large array of 3D points into 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. 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. 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. Thanks for any help that anyone can give.

CodePudding user response:

you can use x = df.to_numpy().flatten() to flatten your data and then save it to csv using np.savetxt.

  • Related