Skip to main content

Posts

Showing posts with the label 27.Replace all missing values in a data frame with a 999 .

ads1

27.Replace all missing values in a data frame with a 999 .

27.Replace all missing values in a data frame with a 999 .  Solution :-  import pandas as pd import numpy as np Srec={'sid':[101,102,103,104,np.nan,106,107,108,109,110], 'sname':['Amit','Sumit',np.nan,'Aman','Rama','Neeta','Amjad','Ram','Ilma','Raja'], 'smarks':[98,67,np.nan,56,38,98,67,np.nan,56,np.nan], 'sgrade':[np.nan,np.nan,'A1','C1','D','A1','B2',np.nan,'B2','A2'], 'remark':['P','P','P','F',np.nan,'P','P','F','P','P'], 'mobile':[9990009991,9990009992,9990009993,np.nan,9990009995,np.nan, 9990009997, 9990009998, np.nan,9999010000]}       # Convert the dictionary into DataFrame  df=pd.DataFrame(Srec) print("\n- Dataframe Before Replacing NaN with 999-\n")  print(df) #Replace missing value with zeros print("\n-After Replacing

ads2