Skip to content

Instantly share code, notes, and snippets.

@selva86
Created September 27, 2021 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selva86/6057d370fe5c4448bd2cfe0f99237666 to your computer and use it in GitHub Desktop.
Save selva86/6057d370fe5c4448bd2cfe0f99237666 to your computer and use it in GitHub Desktop.
import pandas as pd
import random
df_original = pd.read_csv('../Datasets/titanic.csv')
df_original = df_original.dropna()
df_original.reset_index(inplace=True)
# Introduce missing values
random.seed(15)
k = 15
na_index = random.sample(range(df_original.shape[0]), k)
# Replace the values corresponding to the index with np.nan
df_missing = df_original.copy()
df_missing.loc[na_index, 'Age'] = np.nan
df_missing.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment