Code Sample, a copy-pastable example if possible
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.rand(10,3))
df['col'] = 'A'
df.div(df.iloc[:, 0], axis = 0)
Problem description
This throws the following error:
Traceback (most recent call last):
File "<ipython-input-22-b922d0177cba>", line 5, in <module>
df.div(df.iloc[:, 0], axis = 0)
File "C:\Users\flabriol\AppData\Local\Continuum\Anaconda2\lib\site-packages\pandas\core\ops.py", line 1062, in f
return self._combine_series(other, na_op, fill_value, axis, level)
File "C:\Users\flabriol\AppData\Local\Continuum\Anaconda2\lib\site-packages\pandas\core\frame.py", line 3510, in _combine_series
fill_value=fill_value)
File "C:\Users\flabriol\AppData\Local\Continuum\Anaconda2\lib\site-packages\pandas\core\frame.py", line 3535, in _combine_match_index
return self._constructor(func(left.values.T, right.values).T,
File "C:\Users\flabriol\AppData\Local\Continuum\Anaconda2\lib\site-packages\pandas\core\ops.py", line 993, in na_op
mask = notnull(xrav) & notnull(yrav)
**ValueError: operands could not be broadcast together with shapes (40,) (10,)**
Expected Output
I had hard time understanding this error has nothing to do with the shape of the columns but with their dtypes.
Probably a TypeError like TypeError: Could not operate 1.0 with block values unsupported operand type(s) for /: 'str' and 'float'
would have been better
Output of pd.show_versions()
Comment From: gfyoung
@FXLab91 : I ran this code myself, and the first exception that I get is in fact regarding dtypes
. The second exception is the one that you get.
Could you check your output / stacktrace to see whether you get more than just that one error message?
Comment From: FXLab91
@gfyoung : I tried to run the code again, but the stacktrace is just what I reported in the first post. I am running it on iPython console, should it matter.
Comment From: gfyoung
1) It should not matter. I ran the code in IPython
as well, and I can see both errors. It could be that your sys.tracebacklimit
is too small for all the error messages to be displayed.
2) I see you are using pandas
0.18.1. We are in fact now at 0.20.3
- perhaps the discrepancy is due to the fact that you have a very old pandas
version. Could you try upgrading and see if that helps?
Comment From: gfyoung
@FXLab91 : Did my upgrade (or any of my) suggestion(s) help? (I see you :+1: my comment)
Comment From: gfyoung
Closing as I can't reproduce the issue. Please ping this issue again if it rears its head once more. Thanks!