-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: pd.DataFrame.mul has not support fill_value? #61581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @TungPhaSanh , It seems the example code doesn't work because I have tried this on the main branch, but >>> 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 |
Thanks @sanggon6107 My bad. Sorry with my example, the true one is:
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. |
Thanks for the report. Your example doesn't reproduce for me on latest release (2.3.0) with 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' |
Hi @asishm , I have face this error in my project, when I try it. Here is my code: adjusted_data[["Open", "High", "Low", "Close"]] = adjusted_data[
["Open", "High", "Low", "Close"]
].mul(adjusted_data["Multiplier"], axis=0, fill_value=1)
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_9980\1777838207.py in ?()
2 listed_data, adjustment_multiplier, left_on="Ticker", right_index=True, how="left"
3 )
4 adjusted_data[["Open", "High", "Low", "Close"]] = adjusted_data[
5 ["Open", "High", "Low", "Close"]
----> 6 ].mul(adjusted_data["Multiplier"], axis=0, fill_value=1)
7 adjusted_data
~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\pandas\core\frame.py in ?(self, other, axis, level, fill_value)
8386 @Appender(ops.make_flex_doc("mul", "dataframe"))
8387 def mul(
8388 self, other, axis: Axis = "columns", level=None, fill_value=None
8389 ) -> DataFrame:
-> 8390 return self._flex_arith_method(
8391 other, operator.mul, level=level, fill_value=fill_value, axis=axis
8392 )
~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\pandas\core\frame.py in ?(self, other, op, axis, level, fill_value)
8264
8265 if isinstance(other, Series) and fill_value is not None:
8266 # TODO: We could allow this in cases where we end up going
8267 # through the DataFrame path
-> 8268 raise NotImplementedError(f"fill_value {fill_value} not supported.")
8269
8270 other = ops.maybe_prepare_scalar_for_op(other, self.shape)
8271 self, other = self._align_for_op(other, axis, flex=True, level=level)
NotImplementedError: fill_value 1 not supported. For more information: But when I try the following: adjusted_data[["Open", "High", "Low", "Close"]] = adjusted_data[
["Open", "High", "Low", "Close"]
].mul(adjusted_data["Multiplier"].fillna(1), axis=0) it is okay. |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
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
2.3.0
The text was updated successfully, but these errors were encountered: