file_location3 = "F:/python/course1_downloads/City_Zhvi_AllHomes.csv"
housing = pd.read_csv(file_location3)
housing.set_index(['State','RegionName'],inplace=True)
housing = housing.iloc[:, 49:]
housing = housing.groupby(pd.PeriodIndex(housing.columns,freq='Q'),axis=1).mean()
data = housing
data = data.iloc[:,'2008q3' : '2009q2']
The error that I am getting is:
cannot do slice indexing on
'<class 'pandas.core.indexes.period.PeriodIndex'>
with these indexers[2008q3]
of<'class 'str'>
def price_ratio(row):
return (row['2008q3'] - row['2009q2']) / row['2008q3']
data['up&down'] = data.apply(price_ratio, axis=1)
This gives me error: KeyError: ('2008q3', 'occurred at index 0')
Try:
data.loc[:,'2008q3':'2009q2']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With