Deleting Missing Values
Goal¶
This post aims to introduce how to delete missing values using pandas
in python.
Libraries¶
In [3]:
import pandas as pd
import numpy as np
Create DataFrame¶
In [13]:
df = pd.DataFrame(np.random.randn(6, 4), columns=list('ABCD'))
df
Out[13]:
In [14]:
# create missing values
df.loc[3, 'B'] = None
df.loc[4, 'D'] = None
df
Out[14]:
Deleting Missing Values¶
In [15]:
# identify the index by fillna
df.isna()
Out[15]:
In [21]:
df.isna().any(axis=1)
Out[21]:
In [23]:
# Deleteging the rows containing NaN
df.loc[~df.isna().any(axis=1), :]
Out[23]:
In [24]:
# Deleteging the ciks containing NaN
df.loc[:, ~df.isna().any(axis=0)]
Out[24]:
Comments
Comments powered by Disqus