-2

Basically, I want to write the data I have onto a .csv file in a specific layout. I have three arrays (one with x-coordinates, one with y-coordinates and one with z-coordinates) and I want them to be in three columns on the csv file.

For example, my arrays are:

x_array = [1,2,3,4,5]
y_array = [6,7,8,9,0]
z_array = [1,2,3,4,5]

and on the csv file they should look like this:

1,6,1
2,7,2
3,8,3
4,9,4
5,0,5

So far I have tried to use panda dataframe, but I cannot quite unpack this the way I need to later on, so I need a different method. I am out of ideas.

Thank you.

Sime66
  • 1
  • Does this answer your question? [Matrix Transpose in Python](https://stackoverflow.com/questions/4937491/matrix-transpose-in-python) – Elazar Aug 02 '21 at 10:48
  • Just rotate the array before you convert it :) – mama Aug 02 '21 at 11:07

1 Answers1

0

Just rotate the array before you convert it into csv

Here is an example of what you could do :

>>> x_array = [1,2,3,4,5]
>>> y_array = [6,7,8,9,0]
>>> z_array = [1,2,3,4,5]
>>> xyz_array = [x_array, y_array, z_array]
>>> xyz_array = list(zip(*xyz_array[::-1]))
>>> for x in xyz_array:
...     for y in x:
...             print(f'{y},', end='')
...     print()
... 
1,6,1,
2,7,2,
3,8,3,
4,9,4,
5,0,5,
mama
  • 2,046
  • 1
  • 7
  • 24