Pandas Date Converter

I'm having trouble parsing the dates of a file while reading it with Pandas.

I am using python (x, y) version 2.7.

The file I am trying to read has the following format:

"
SomethingSomethig,
SomethingSomethig,
SomethingSomethig,
Est,dir,Vmed,raj,Vmin,desv.padrão,date,
555,162,5.30,10.10,6.50,0.67,200901010000,
555,135,6.10,10.90,6.40,0.67,200901010010,
555,156,5.90,11.00,5.90,0.76,200901010020,
555,178,6.90,10.90,5.30,0.96,200901010030,
555,200,9.80,11.20,6.10,0.96,200901010040,
555,100,9.70,11.40,5.70,0.96,200901010050,"

      

Using the following line of code:

dados = read_csv(file, sep=",", skiprows=3, index_col=6,parse_dates=True)

      

output:

""
Int64Index: 157968 entries, 200901010000 to 201112312350
Data columns:
Est            157968  non-null values
dir            157968  non-null values
Vmed           157968  non-null values
raj            157968  non-null values
Vmin           157968  non-null values
desv.padr?o    157968  non-null values
Unnamed: 7     157968  non-null values
dtypes: float64(4), int64(2), object(1)
""

      

If the dates are not parsed. And I am getting an error when I try to use dates to do any calculations. I don't know how to use the converter and can really use your help.

+3


source to share


1 answer


Works great for me:

In [3]: read_csv('/home/wesm/tmp/foo.txt', skiprows=3, index_col=6, parse_dates=True)
Out[3]: 
                     Est  dir  Vmed   raj  Vmin  desv.padrão  Unnamed: 7
date                                                                     
2009-01-01 00:00:00  555  162   5.3  10.1   6.5          0.67         NaN
2009-01-01 00:10:00  555  135   6.1  10.9   6.4          0.67         NaN
2009-01-01 00:20:00  555  156   5.9  11.0   5.9          0.76         NaN
2009-01-01 00:30:00  555  178   6.9  10.9   5.3          0.96         NaN
2009-01-01 00:40:00  555  200   9.8  11.2   6.1          0.96         NaN
2009-01-01 00:50:00  555  100   9.7  11.4   5.7          0.96         NaN

      



Which version of pandas are you using? Maybe there is a problem that only represents the whole file?

+5


source







All Articles