In: Computer Science
Create a pandas dataframe and then impute missing values .
data = { 'test' : [1,2,3,4,10,15]
'missing' : [1,2,4,None,5,7] }
replace the missing values in the missing table column with mean values using mean imputation
============
i am trying like this but i am not getting correct output and getting confused please explain with proper output and explanation
import pandas as pd
pd.DataFrame(data)
temp = pd.DataFrame(data).fillna(np.mean())
temp ['missing'] . fillna(temp['missing'].mean())
================
i am too much confused please write proper program with complete output
you missed iplace=True inside fillna method
data = { 'test' : [1,2,3,4,10,15],
'missing' : [1,2,4,None,5,7] }
import pandas as pd
import numpy as np
pd.DataFrame(data)
temp = pd.DataFrame(data)
print(temp)
temp ['missing'].fillna(temp['missing'].mean(),inplace=True)
print("\nAfter replacing none values to mean value")
print(temp)
when more columns contains None then
data = { 'test' : [1,2,None,4,10,15],
'missing' : [1,2,4,None,5,7] }
import pandas as pd
import numpy as np
pd.DataFrame(data)
temp = pd.DataFrame(data)
print(temp)
#temp ['missing'].fillna(temp['missing'].mean(),inplace=True)
temp.fillna(temp.mean(),inplace=True)
print("\nAfter replacing none values to mean value")
print(temp)