我有一個資料集,其中空值是
df.isnull().sum()
country 0
country_long 0
name 0
gppd_idnr 0
capacity_mw 0
latitude 46
longitude 46
primary_fuel 0
other_fuel1 0
other_fuel2 0
other_fuel3 908
commissioning_year 380
owner 0
source 0
url 0
geolocation_source 0
wepp_id 908
year_of_capacity_data 388
generation_gwh_2013 524
generation_gwh_2014 507
generation_gwh_2015 483
generation_gwh_2016 471
generation_gwh_2017 465
generation_data_source 0
estimated_generation_gwh 908
我嘗試了 mean mode max min 和 std 所有方法,但是當我嘗試時,所有空值都沒有洗掉
df['wepp_id']=df['wepp_id'].replace(np.NAN,df['wepp_id'].mean())
它不作業同樣的事情發生在中值,標準和最小值,最大值也
uj5u.com熱心網友回復:
嘗試 df['wepp_id']=df['wepp_id'].fillna(df['wepp_id'].mean())
如果這不起作用,則意味著您的列不是數字型別。如果是字串型別,那么你需要先這樣做:
df['wepp_id'] = df['wepp_id'].astype(float)
然后運行第一行中的命令。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/342463.html
上一篇:python中的重力加速度
下一篇:從串列中選擇n個關鍵字
