Pregunta

I'm trying to import data (csv type) with Spyder (it has an Import Data option-green arrow, do you know what is this command by default?) and I get this error: 'NoneType' object has no attribute 'send'

Also, I have tried with numpy.genfromtxt("file.csv", delimiter = ',') and numpy.loadtxt("file.csv", delimiter = ',') but don't work. I am working with Python 3.2.3 and I use numpy and scipy (imported before execute the previuos commands).

Example of my datafile:

TIMESTAMP,TIMESTAMP,TIMESTAMP,TIMESTAMP,RECORD,Net_Shortwave_Avg (Wm-2),Net_Longwave_Avg(Wm-2),Net_Rad_Avg(Wm-2 )
12/21/2012 11:00:00,1100,12,11,0,556.0623,-131.1266,424.9357
12/21/2012 11:01:00,1101,12,11,1,564.877,-132.1396,432.7373
¿Fue útil?

Solución

The loadtxt function, by default, tries to convert everything to a float. It is getting confused by the text in the header and the datetime objects in the first column. You can tell it how to use the datetime objects, and you can also have it read the header. However, the simplest thing to do is to tell loadtxt to ignore the first row and the first column, like this:

data = np.loadtxt('data.csv',delimiter=',',usecols=range(1,7),skiprows=1)

It might also be convenient to unpack you data into separate variables, like this (I'm kinda guessing what some of the fields are):

day,hour,minute,Net_Shortwave_Avg,Net_Longwave_Avg,Net_Rad_Avg =  np.loadtxt('data.csv',delimiter=',',usecols=range(1,7),skiprows=1,unpack=True)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top