Skip to content

Instantly share code, notes, and snippets.

@jaradc
Created November 22, 2017 04:57
Show Gist options
  • Save jaradc/aaf8177da4fa9e6d7c35394ae215a7d4 to your computer and use it in GitHub Desktop.
Save jaradc/aaf8177da4fa9e6d7c35394ae215a7d4 to your computer and use it in GitHub Desktop.
This is a good example of inplace not working as-expected
df = pd.DataFrame(
{'Label': [np.nan, np.nan, 'Label1', 'Label2'],
'URL': ['https://www.website.com/where-to-buy',
np.nan, np.nan, 'https://www.website.com/store']
}, columns=['Label', 'URL'])
# this does not actually replace inplace!
df[['Label', 'URL']].fillna('', inplace=True)
# you have to assign it or use a dict
self.data.fillna({'Campaign': '', 'Final URL': ''}, inplace=True)
# or
df[['Label', 'URL']] = df[['Label', 'URL']].fillna('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment