Skip to content

Instantly share code, notes, and snippets.

@selva86
Created May 19, 2021 11:21
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/50d9d01cbfd3d125ff81df147cac86aa to your computer and use it in GitHub Desktop.
Save selva86/50d9d01cbfd3d125ff81df147cac86aa to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
df = pd.read_csv('Datasets\Titanic.csv').sample(50, random_state=100)
n_missing = np.random.randint(4, 15, 1)
for i in range(n_missing):
row = np.random.randint(1, df.shape[0])
df.at[row, "Age"] = pd.NA
for i in range(n_missing):
row = np.random.randint(1, df.shape[0])
df.at[row, "Fare"] = pd.NA
for i in range(n_missing):
row = np.random.randint(1, df.shape[0])
df.at[row, "Sex"] = pd.NA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment