Import NumPy under the alias np
.
import numpy as np
Import pandas under the alias pd
.
import pandas as pd
Given the DataFrame data
, remove all of its rows that contain null values using the pandas method discussed in the lesson.
data = pd.DataFrame(np.array([[np.nan, 8, 12],[np.nan, 16, np.nan],[4, 13, 45]]))
#Solution goes here
data.dropna()
0 | 1 | 2 | |
---|---|---|---|
2 | 4.0 | 13.0 | 45.0 |
Given the DataFrame data
, remove all of its columns that contain null values using the pandas method discussed in the lesson.
#Solution goes here
data.dropna(axis=1)
1 | |
---|---|
0 | 8.0 |
1 | 16.0 |
2 | 13.0 |
Given the DataFrame data
, replace all of its null values with 💩
(copy and paste it).
data.fillna('💩')
0 | 1 | 2 | |
---|---|---|---|
0 | 💩 | 8.0 | 12 |
1 | 💩 | 16.0 | 💩 |
2 | 4 | 13.0 | 45 |
Given the DataFrame data
, replace all of its null values with the mean value across the entire DataFrame.
data.fillna(data.mean())
0 | 1 | 2 | |
---|---|---|---|
0 | 4.0 | 8.0 | 12.0 |
1 | 4.0 | 16.0 | 28.5 |
2 | 4.0 | 13.0 | 45.0 |