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
Suppose I have the following dataframe and series:
In [20]: df = pd.DataFrame(np.ones((3,4)), columns=pd.MultiIndex.from_product([['A', 'B'],['a', 'b']]))
In [21]: s = pd.Series({'a':1, 'b':2})
In [22]: df
Out[22]:
A B
a b a b
0 1 1 1 1
1 1 1 1 1
2 1 1 1 1
In [23]: s
Out[23]:
a 1
b 2
dtype: int64
Trying to multiply this by the columns, and matching on the second level, gives the following error:
In [24]: df.mul(s, axis=1, level=1)
...
File "C:\Anaconda\lib\site-packages\pandas\core\index.py", line 1786, in _join_multi
raise ValueError("cannot join with no level specified and no overlapping names")
ValueError: cannot join with no level specified and no overlapping names
In any case, this is a wrong error message, as I did specify a level.
Further, this does work and gives the expected output with a named level instead of a integer level:
In [25]: df2 = df.copy()
...: df2.columns.names = ['l0', 'l1']
In [35]: df2.mul(s, axis=1, level='l1') # <-- works
Out[35]:
l0 A B
l1 a b a b
0 1 2 1 2
1 1 2 1 2
2 1 2 1 2
Am I correct that this should also work with integer levels?
The text was updated successfully, but these errors were encountered:
Suppose I have the following dataframe and series:
Trying to multiply this by the columns, and matching on the second level, gives the following error:
In any case, this is a wrong error message, as I did specify a level.
Further, this does work and gives the expected output with a named level instead of a integer level:
Am I correct that this should also work with integer levels?
The text was updated successfully, but these errors were encountered: