对象类型<class'pandas.core.frame.DataFrame'>没有名为X的轴

时间:2019-11-21 15:27:47

标签: python-3.x pandas pandas-groupby

我正在尝试仅提取数据的第一部分,即多级数据框中的2006年条目。下面的代码代码不起作用:

df2 = df.set_index('Testdate')
df_h = df2.groupby([pd.Grouper(freq='Y'),'Animal_ID'])
df_h = df_h.count()
h06 = df_h.loc('2006-12-31') 

一些可能有用的输出:

In[1]: type(df_h)
Out[1]: pandas.core.frame.DataFrame
In[2]: df_h
Out[2]:
                      Herd_ID  Parity  SH  
Testdate   Animal_ID                                            
2006-12-31 638              1       1   1   
           1189             1       1   1   
           1190             1       1   1  
           1193             1       1   1   
           1208             1       1   1   
                      ...     ...  ..  .. 
2018-12-31 285813           1       1   1  
           285814           2       2   2  
           285815           1       1   1   
           285818           1       1   1   
           285821           1       1   1   
In[3]: h06 = df_h.loc('2006-12-31')
Out[3]: Traceback (most recent call last):

  File "<ipython-input-491-3b143ba77aa9>", line 1, in <module>
    h06 = df_h.loc('2006-12-31')

  File "path", line 112, in __call__
    axis = self.obj._get_axis_number(axis)

  File "path", line 411, in _get_axis_number
    raise ValueError("No axis named {0} for object type {1}".format(axis, cls))

ValueError: No axis named 2006-12-31 for object type <class 'pandas.core.frame.DataFrame'>


0 个答案:

没有答案