Code Sample, a copy-pastable example if possible
df=pd.DataFrame([(i+j,i-j,i*j) for i in range(0,4) for j in (2,6)])
df.columns=['a','b','c']
df.loc[:,['a','c']].div(df['b'],axis=0)
Output: "ValueError: putmask: mask and data must be the same size"
This message is too ambiguous: what size is it referring to ? After some investigation, I understood that data size was referring to divisor data type, not to the size (length) of the DataFrame and Series, which I wrongly understood was the message referring to: type(df['b'][0]): class 'numpy.int64' (error) type((df['b']/1)[0]): class 'numpy.float64' (no error)
Therefore, changing the last line to: df.loc[:,['a','c']].div(df['b']/1,axis=0) worked:
Expected Output
a c
0 -1.000000 -0.000000 1 -1.000000 -0.000000 2 -3.000000 -2.000000 3 -1.400000 -1.200000 4 inf inf 5 -2.000000 -3.000000 6 5.000000 6.000000 7 -3.000000 -6.000000
output of pd.show_versions()
INSTALLED VERSIONS
commit: None python: 3.4.3.final.0 python-bits: 64 OS: Linux OS-release: 3.13.0-85-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: fr_FR.UTF-8
pandas: 0.13.1 Cython: None numpy: 1.8.2 scipy: 0.13.3 statsmodels: None IPython: None sphinx: None patsy: None scikits.timeseries: None dateutil: 2.0 pytz: 2012c bottleneck: None tables: 3.1.1 numexpr: 2.2.2 matplotlib: 1.3.1 openpyxl: None xlrd: None xlwt: None xlsxwriter: None sqlalchemy: None lxml: 3.3.3 bs4: 4.2.1 html5lib: 0.999 bq: None apiclient: None
Comment From: sinhrks
This works on my env. Pls try the latest version (0.18.1).
df.loc[:,['a','c']].div(df['b'],axis=0)
# a c
# 0 -1.000000 -0.000000
# 1 -1.000000 -0.000000
# 2 -3.000000 -2.000000
# 3 -1.400000 -1.200000
# 4 inf inf
# 5 -2.000000 -3.000000
# 6 5.000000 6.000000
# 7 -3.000000 -6.000000
Also, properly using markup is appreciated.
Comment From: jreback
@camilaran you have a quite old version. Since it works on latest release, closing.