I am trying to select some rows between two dates inside a Dataframe. The problem is when I try, I get:
Empty DataFrame
I import some financial historical data and then puting the date column as the index (DatetimeIndex).
When I try to individually select one row with a date, it works. It's when I try with a date interval that it doesn't (even if I checked each row individually).
I tried to fill possible empty cells with fillna(), without success.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
#Open Euro Euro Stoxx 50 csv file, rename columns and set dates as index
euro_stoxx_50 = pd.read_csv('STOXX50E.csv', parse_dates = True, index_col = 0)
euro_stoxx_50.columns = ['open', 'high', 'low', 'close', 'volume', 'adj close']
euro_stoxx_50.index.names = ['date']
My problem with examples:
print euro_stoxx_50.head()
print euro_stoxx_50.index
print euro_stoxx_50.empty
print euro_stoxx_50['2012':'2015'].empty
Will give:
date open high low close volume adj close
2015-09-25 3113.16 3113.16 3113.16 3113.16 0 3113.16
2015-09-24 3019.34 3019.34 3019.34 3019.34 0 3019.34
2015-09-23 3079.99 3079.99 3079.99 3079.99 0 3079.99
2015-09-22 3076.05 3076.05 3076.05 3076.05 0 3076.05
2015-09-21 3184.72 3184.72 3184.72 3184.72 0 3184.72
<class 'pandas.tseries.index.DatetimeIndex'>
[2015-09-25, ..., 1986-12-31]
Length: 7396, Freq: None, Timezone: None
False
True
And
print euro_stoxx_50['2012-9-12']
print euro_stoxx_50['2012-9-13']
print euro_stoxx_50['2012-9-12':'2012-9-13']
will give:
date open high low close volume adj close
2012-09-12 2564.8 2564.8 2564.8 2564.8 0 2564.8
date open high low close volume adj close
2012-09-13 2543.22 2543.22 2543.22 2543.22 0 2543.22
Empty DataFrame
Columns: [open, high, low, close, volume, adj close]
Index: []
edit
Thanks for any help!