Create a dummy data frame and add NA values to it¶
In [1]:
import pandas as pd
import numpy as np
In [18]:
df=pd.DataFrame(np.array([["A",np.nan,"C"],[np.nan,2,3]])).T
df.columns=['Name','ID']
df
Out[18]:
Name | ID | |
---|---|---|
0 | A | nan |
1 | nan | 2 |
2 | C | 3 |
Using np.where to replace nan values everywhere¶
In [31]:
df1=np.where(df.eq('nan'), 0, df)
df2=pd.DataFrame(df1)
df2.columns=['Name','ID']
df2
Out[31]:
Name | ID | |
---|---|---|
0 | A | 0 |
1 | 0 | 2 |
2 | C | 3 |
No comments:
Post a Comment