fillna(inplace=True) does not work with columns selected by loc
See original GitHub issuenot only multiple columns, but also one column.
df.loc[df.id==123, 'num'].fillna(0, inplace=True)
doesn’t work ,
but df.loc[df.id==123, 'num'] = 123
works
why not edit the fillna function to adapt it in the future. It seems like a bug.
_Originally posted by @shuiyuejihua in https://github.com/pandas-dev/pandas/issues/14858#issuecomment-428979311_
Hi, I met with the same problem. Now that df.loc[df.id==123, 'num'] = 123
works, which means the operation takes effect on original df
, why fillna(inplace=True) doesn’t work? This is really wired , and seems haven’t been fixed. My pandas version is 0.25.3
.
Any comment or explaination are welcome, thanks!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Pandas won't fillna() inplace - Stack Overflow
I'm trying to fill NAs with "" on 4 specific columns in a data frame that are string/ ...
Read more >pandas.DataFrame.fillna() - Explained by Examples
fillna () method is used to fill NaN/NA values on a specified column or on an entire DataaFrame with any given value. You...
Read more >Why You Should Probably Never Use pandas inplace=True
This article will explain what the pandas inplace=True keyword means, how it behaves, and why you should probably never use it.
Read more >pandas.DataFrame.fillna — pandas 1.5.2 documentation
Values not in the dict/Series/DataFrame will not be filled. This value cannot be a ... Object with missing values filled or None if...
Read more >pandas: Replace missing values (NaN) with fillna() - nkmk note
Specify a dictionary of {column_name: value} . If a column name is not specified, missing values in its column are retained (= not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jreback no warning is currently raised for me
In general - see #16529 (or https://youtu.be/hK6o_TDXXN8)