-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
ENH: column-wise DataFrame.fillna with Series/Dict value #38352
Conversation
doc/source/whatsnew/v1.2.0.rst
Outdated
@@ -260,6 +260,7 @@ Other enhancements | |||
- Added :meth:`~DataFrame.set_flags` for setting table-wide flags on a Series or DataFrame (:issue:`28394`) | |||
- :meth:`DataFrame.applymap` now supports ``na_action`` (:issue:`23803`) | |||
- :class:`Index` with object dtype supports division and multiplication (:issue:`34160`) | |||
- :meth:`DataFrame.fillna` can fill NA values column-wise with a dictionary or :class:`Series` (:issue:`4514`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to 1.3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
df = DataFrame([[np.nan, 2], [3, np.nan], [np.nan, np.nan]], columns=list("AB")) | ||
s = Series([100, 200, 300]) | ||
|
||
expected = DataFrame( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if we have a datetime column mixed in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We end up with object dtype:
In [5]: df = pd.DataFrame([[np.nan, 2], [3, np.nan], [np.nan, np.nan]], columns=list("AB"))
...: s = pd.Series(pd.to_datetime([100, 200, 300], unit="ns"))
...:
...: result = df.fillna(s, axis=1, downcast="infer")
...: result
Out[5]:
A B
0 1970-01-01 00:00:00.000000100 2.0
1 3.0 1970-01-01 00:00:00.000000200
2 1970-01-01 00:00:00.000000300 1970-01-01 00:00:00.000000300
In [6]: result.dtypes
Out[6]:
A object
B object
dtype: object
In [8]: df = pd.DataFrame({"A": pd.to_datetime([np.nan, 2, np.nan]), "B": pd.to_datetime([3, np.nan, np.nan])})
...: s = pd.Series([100, 200, 300])
...:
...: result = df.fillna(s, axis=1, downcast="infer")
...: result
Out[8]:
A B
0 100 1970-01-01 00:00:00.000000003
1 1970-01-01 00:00:00.000000002 200
2 300 300
In [9]: result.dtypes
Out[9]:
A object
B object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this what we want?
Green + addressed comments |
Thanks for the PR but it appears this has gone stale. Looks fairly close but let us know if you'd like to continue by merging master and targeting 1.4 |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Picking up #30922