You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [24]: df=pd.DataFrame({
....: 'exp' : ['A']*3+ ['B']*3,
....: 'var1' : range(6),
....: })
In [25]: df=df.set_index(['exp'])
In [26]: df.index.namesOut[27]: ['exp']
In [28]: dfOut[28]:
var1expA0A1A2B3B4B5In [29]: try:
....: df.groupby(level='exp').size()
....: exceptValueErrorase:
....: print('index can not be accessed by name')
....: print(e)
....:
indexcannotbeaccessedbynamelevel>0onlyvalidwithMultiIndex# at this point I would argue that the level 'exp' is level 0,# and therefore this should work.In [29]: df1=df.groupby(level=0).size()
In [30]: df1Out[30]:
expA3B3dtype: int64
The text was updated successfully, but these errors were encountered:
which returns a ValueError: level name a is not the name of the index.
Is this behaviour expected? If it is, it would still be very handy to have a way to do this quickly on index names without needing to check if it is a MultiIndex before.
The text was updated successfully, but these errors were encountered: