Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas Date converter

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

I'm using python(x,y), version 2.7.

The file i'm 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)

the output is:

""
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)
""

With the dates not parsed. And I get an error when tryin to use the dates to perform any kind of calculations. I dont know how to use the converter and could really use your help.

like image 226
Fernando Mourão Avatar asked Dec 30 '25 22:12

Fernando Mourão


1 Answers

Works fine 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

What version of pandas are you using? Maybe there's a problem that only presents itself with the whole file?

like image 87
Wes McKinney Avatar answered Jan 05 '26 05:01

Wes McKinney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!