PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 29, 2022

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

 August 29, 2022     3d, csv, excel, python     No comments   

Issue

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.


Solution

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



Answered By - MosGeo
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing