Select date from imported CSV using pandas / python

I have a CSV file with daily data:

some 19 more header rows Werte 01.01.1971 07:00:00 ; 0.0 02.01.1971 07:00:00 ; 1.2 ...and so on 

which I import with:

 RainD=pd.read_csv('filename.csv',skiprows=20,sep=';',dayfirst=True,parse_dates=True) 

As a result, I get

 In [416]: RainD Out[416]: <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 14976 entries, 1971-01-01 07:00:00 to 2012-01-01 07:00:00 Data columns: Werte: 14976 non-null values dtypes: object(1) 

So this is a DataFrame, but maybe the Timeseries could be right? But how do I import it as such? The pandas documentation contains a dtype list in read_csv but does not contain information about what I can / should specify.

But, on the other hand, DatetimeIndex: it seems to me that pandas is fully aware of the fact that I'm doing dates here, but still makes it a Dataframe. And for this, something like RainD['1971'] just leads to the u'no item named 1971' Key error.

I have the feeling that I just missed something really obvious, as time series analysis was apparently a pandas thing.

Another my first idea was that pandas might be confused by the fact that the dates are written in the correct (i.e. dd.mm.yyyy;)) way, but a RainD.head() shows me that I could digest this just fine.

JC Relations

+1
source share
1 answer

EdChum df[df.index.year == 1971] solved my problem.

I may have other problems (e.g. an outdated version of pandas), but for now I can continue to work.

+1
source

All Articles