Pandas version checks
-
[x] I have checked that this issue has not already been reported.
-
[x] I have confirmed this bug exists on the latest version of pandas.
-
[x] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
df = pd.DataFrame(np.arange(12).reshape(3,4))
s = [1,pd.NA,3]
df.mul(s, axis="columns", fill_value=0)
Issue Description
It raise error: fill_value=0 is not supported
Expected Behavior
It should return the result with filled NA value of 0
Installed Versions
Comment From: sanggon6107
Hi @TungPhaSanh ,
It seems the example code doesn't work because s
only has 3 elements - I think it needs 4.
I have tried this on the main branch, but mul
seems to work fine when fill_value=0
.
>>> import pandas as pd
>>> import numpy as np
>>> df = pd.DataFrame(np.arange(12).reshape(3,4))
>>> df
0 1 2 3
0 0 1 2 3
1 4 5 6 7
2 8 9 10 11
>>> s = [1,pd.NA,3, 4]
>>> s
[1, <NA>, 3, 4]
>>> df.mul(s, axis="columns", fill_value=0)
0 1 2 3
0 0 0 6 12
1 4 0 18 28
2 8 0 30 44
Comment From: TungPhaSanh
Thanks @sanggon6107
My bad. Sorry with my example, the true one is:
import pandas as pd df = pd.DataFrame(np.arange(12).reshape(3,4)) s = [1,pd.NA,3] df.mul(s, axis="index", fill_value=0) # index instead of columns
I have try it, it is okay, but sometimes in my project it raise error fill_value=0 is not supported. I have to fillna first before doing multiplication.
Comment From: asishm
Thanks for the report. Your example doesn't reproduce for me on latest release (2.3.0) with axis='index'
.
Can you confirm your example provided currently fails for you and if so, please provide the full traceback. If not, please update your post with a reproducible example. Thanks!
>>> df
0 1 2 3
0 0 1 2 3
1 4 5 6 7
2 8 9 10 11
>>> s = [1,pd.NA,3]
>>> df.mul(s, axis="index", fill_value=0)
0 1 2 3
0 0 1 2 3
1 0 0 0 0
2 24 27 30 33
>>> pd.__version__
'2.3.0'