0

This question is somehow a continuation of this one. I've been able to correctly takes what I'm interested in a downloadable csv file as follow

import time
import urllib2
import csv
import sys
import pandas
response=urllib2.urlopen('http://www.euribor-ebf.eu/assets/modules/rateisblue/processed_files/hist_EURIBOR_2012.csv')
localFile = open('file.csv', 'w')
localFile.write(response.read())
localFile.close()
df2=pandas.io.parsers.read_csv('file.csv',index_col = 0, parse_dates = True, dayfirst = True)[:15].transpose()[:200] ## transpose in order to be compatible with pandas dataframe
df2 = df2.dropna() ## drop the values which are not-a-number
eur3m = df2['3m']

Now eur3m is a Series in Pandas and I would like to have information on a given time period. I know I can generate daterange with DateRange. What I would basically like to do is the have for example statics over 1 month period (let's say mean and std in the period from 1 of July 2012 and 31 of July 2012). For some reasons, although I read the csv file trying to parse the date considering that these dates are in european format (DD/MM/YYYY) I'm not able to follow this example. Let's say trying something like

day=eur3m.index
i = ((day >= '01/07/2012') & (day <= '31/07/2012')) 

but it does not work. Actually day is an array of string. I can't understand if this is correct. Any help?

Community
  • 1
  • 1
Nicola Vianello
  • 1,916
  • 6
  • 21
  • 26

1 Answers1

1

The dates are originally read in as the column names and pandas currently does not parse the column names into dates. For feature requests, please create a new issue on github: https://github.com/pydata/pandas/issues

For now you can do some post-processing:

eur3m.index = [datetime.datetime.strptime(x, '%d/%m/%Y') for x in eur3m.index]
Chang She
  • 16,692
  • 8
  • 40
  • 25