0

I am working on some csv files and would like to convert them to txt. I have developed a for loop in Python in which the comma is set as field separator. However, I don't know how to import the columns contained in inverted commas ". Here is the code:

import numpy as np

# a=np.genfromtxt('Nuvole_split\Tri_8851.csv', delimiter=',',skip_header=1)
# np.savetxt('Prova.txt', a)

#Conversione nuvole in txt
for i in range (1,9226):
    try:
        a=np.genfromtxt(r'Nuvole_split\Tri_%i.csv' %i, delimiter=',',skip_header=1)
        export=np.transpose((a[:,0],a[:,1],a[:,2]))
        np.savetxt(r'D:\Tesi\VAIA_grosso\Nuvole_split\Conv\Nuvola%i.txt' %i, export)
    except Exception as e:
              print(e)

And this is a snippet of the csv to be converted: Screenshot

I would also like to import the last column but, for now, it returns an error and fills it with nan

Nicola
  • 1
  • 2
  • According to the `genfromtxt` docs, the default load `dtype` is `float`. If a element cannot be interpreted as float, it is loaded as `np.nan`. `float('"1"')` produces such an error. – hpaulj May 30 '22 at 15:22
  • So can I solve it by adding dtype and categorising by columns? – Nicola May 30 '22 at 15:40

0 Answers0