question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fillna(inplace=True) does not work with columns selected by loc

See original GitHub issue

not 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:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MarcoGorellicommented, Feb 25, 2020

@jreback no warning is currently raised for me

1reaction
MarcoGorellicommented, Feb 25, 2020

In general - see #16529 (or https://youtu.be/hK6o_TDXXN8)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found