Professional Documents
Culture Documents
Cleaning
Cleaning
[12]:
import pandas as pd
df=pd.read_csv("weather_data.csv")
df
isnull()
The isnull() method returns a DataFrame object where all the values are replaced with a Boolean value True for NULL values, and otherwise False.
In [17]:
import pandas as pd
df=pd.read_csv("weather_data.csv")
df1=df.isnull()
print(df1.to_string())
notnull
Replace all values in the DataFrame with True for NOT NULL values, otherwise False
In [21]:
import pandas as pd
df=pd.read_csv("weather_data.csv")
df1=df.notnull()
print(df1.to_string())
dropna()
One way to deal with empty cells is to remove rows that contain empty cells.
In [22]:
import pandas as pd
df=pd.read_csv("weather_data.csv")
df1=df.dropna()
print(df1.to_string())
df=pd.read_csv("weather_data.csv")
df1=df.dropna(thresh=3)
print(df1.to_string())
fillna()
method allows us to replace empty cells with a value:
In [24]:
import pandas as pd
df=pd.read_csv("weather_data.csv")
df1 = df.fillna(0)
df1
In [25]:
import pandas as pd
df=pd.read_csv("weather_data.csv")
print(df1)
ffill()
‘ffill’ stands for ‘forward fill’ and will propagate last valid observation forward.
In [26]:
import pandas as pd
df=pd.read_csv("weather_data.csv")
df1 = df.fillna(method='ffill')
print(df1)
df=pd.read_csv("weather_data.csv")
df1 = df.fillna(method='bfill')
print(df1)