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']
我得到的错误是:
无法使用这些索引器对
'<class 'pandas.core.indexes.period.PeriodIndex'>
进行切片索引 ---[2008q3]
<'class 'str'>
现在我收到另一个错误
def price_ratio(row):
return (row['2008q3'] - row['2009q2']) / row['2008q3']
data['up&down'] = data.apply(price_ratio, axis=1)
这给我错误: KeyError: ('2008q3', 'occurred at index 0')
原文由 Gaurav 发布,翻译遵循 CC BY-SA 4.0 许可协议
尝试: