1

I am writing a bunch of data outputted by a for loop into a .csv file I created (below). Having done that, I want to organize it by adding rows and columns at specific locations. I want to use it to add titles for each row and column. How do I go with that? Most examples online do so on csv.reader not writer. I'm a bit confused.

    #the rows and columns i'd like to add, but i also want to insert rows after row 7
row0 = ['GRA1_1']
    row1 = ['','Config 1 - Identical','','','Config 2 - mirrored','','','Config 3 - rotated','']
    column0 = ['Projection of gyro on plane + xy (orth: +z)','Projection of gyro on plane + xz (orth: +y)','Projection of gyro on plane + yz (orth: +x)','Projection of gyro on plane - xy (orth: -z)','Projection of gyro on plane - xz (orth: -y)','Projection of gyro on plane - yz (orth: -x)']
    
with open('/Users/path/gyro_config.csv', 'a', newline='') as f:
        writer = csv.writer(f, delimiter=',')
        writer.writerows(gyro_projections)

I also found this link and tried to implement it but it gave me this error:

AttributeError: 'list' object has no attribute 'shape'

https://www.geeksforgeeks.org/insert-row-at-given-position-in-pandas-dataframe/

Eman AlAwadhi
  • 23
  • 1
  • 5
  • 1
    Please explain which exactly tool you want to use, as this is unclear from tags you used: `pandas` xor built-in python module `csv` xor `opencsv` i.e. *a simple csv (comma-separated values) parser library for Java* – Daweo Jun 15 '21 at 08:24
  • [JFYI](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Danila Ganchar Jun 15 '21 at 08:43
  • I prefer using csv but whatever is easier is fine by me too – Eman AlAwadhi Jun 15 '21 at 09:09

0 Answers0