Missing values are not ?
, your functions should be changed:
Here is used DataFrame.loc
for set values by condition:
def replace_val(df):
df.loc[df['Value']=='?', 'Value']= float("NaN")
#alternative
#df['Value'] = df['Value'].replace('?',float("NaN"))
print(df)
For filtering is used boolean indexing
:
def filter_value(df):
df = df.loc['Value' =='?']
print(df)
Last you can change mask with !=
for select all values without ?
:
def replace_with_mean(df):
df.loc['Value' =='?','Value'] = df.loc['Value' !='?','Value'].mean()
print(df)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…