================
by Jawad Haider
03 - Missing Data
Copyright Qalmaqihir
For more information, visit us at
www.github.com/qalmaqihir/
Missing Data
Let’s show a few convenient methods to deal with Missing Data in pandas:
import numpy as np
import pandas as pd
df = pd.DataFrame({'A':[1,2,np.nan],
'B':[5,np.nan,np.nan],
'C':[1,2,3]})
|
A |
B |
C |
0 |
1.0 |
5.0 |
1 |
1 |
2.0 |
NaN |
2 |
2 |
NaN |
NaN |
3 |
|
A |
B |
C |
0 |
1.0 |
5.0 |
1 |
1 |
2.0 |
NaN |
2 |
df.fillna(value='FILL VALUE')
|
A |
B |
C |
0 |
1 |
5 |
1 |
1 |
2 |
FILL VALUE |
2 |
2 |
FILL VALUE |
FILL VALUE |
3 |
df['A'].fillna(value=df['A'].mean())
0 1.0
1 2.0
2 1.5
Name: A, dtype: float64
Great Job! Thats the end of this part.
Don't forget to give a star on github and follow for more curated Computer Science, Machine Learning materials