Skip to content

Instantly share code, notes, and snippets.

@liusy182
Created May 31, 2020 07:11
Show Gist options
  • Select an option

  • Save liusy182/2d20b752dd463b64301eb6b42d37479c to your computer and use it in GitHub Desktop.

Select an option

Save liusy182/2d20b752dd463b64301eb6b42d37479c to your computer and use it in GitHub Desktop.
missing values
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
# dataset: https://www.kaggle.com/camnugent/california-housing-prices
df = pd.read_csv('/kaggle/input/california-housing-prices/housing.csv');
print('\nisnull before:\n', df['total_bedrooms'].isnull().any())
# isnull before:
# True
df['total_bedrooms'].fillna(df['total_bedrooms'].median(), inplace=True)
print('\nisnull after:\n', df['total_bedrooms'].isnull().any())
# isnull after:
# False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment