In [1]:
import pandas as pd
import numpy as np
In [14]:
df=pd.DataFrame(np.array(["A",None,"C"]))
df.columns=['Name']
df
Out[14]:
Name | |
---|---|
0 | A |
1 | None |
2 | C |
Removing rows where Name is NA¶
In [18]:
df[df['Name'].notna()]
Out[18]:
Name | |
---|---|
0 | A |
2 | C |
When we are introducing NaN values in a string, we need to use None. None is recognized as valid NaN values within a string columns.¶
Lets create a dataframe with a numeric column and add NaN values to it¶
In [19]:
df2=pd.DataFrame(np.array([1,2,np.nan]))
df2.columns=['Val']
df2
Out[19]:
Val | |
---|---|
0 | 1.0 |
1 | 2.0 |
2 | NaN |
Removing NaN values¶
In [20]:
df2[df2['Val'].notna()]
Out[20]:
Val | |
---|---|
0 | 1.0 |
1 | 2.0 |