日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python的out模式_如何用python中的DataFrame列的模式替换NA值?

發(fā)布時間:2024/1/23 python 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python的out模式_如何用python中的DataFrame列的模式替换NA值? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我對Python(和本網(wǎng)站)完全陌生,目前正試圖用它們的模式替換特定數(shù)據(jù)幀列中的NA值。我試過了各種不起作用的方法。請幫我看看我做錯了什么:如何用python中的DataFrame列的模式替換NA值?

注意:我正在使用的所有列都是float64類型。我所有的代碼都會運行,但是當我在列中檢查空數(shù)量df[cols_mode].isnull().sum()時,它仍然是一樣的。

方法1:

cols_mode = ['race', 'goal', 'date', 'go_out', 'career_c']

df[cols_mode].apply(lambda x: x.fillna(x.mode, inplace=True))

我試圖Imputer方法太多,但遇到了同樣的結果

方法2:

for column in df[['race', 'goal', 'date', 'go_out', 'career_c']]:

mode = df[column].mode()

df[column] = df[column].fillna(mode)

方法3:

df['race'].fillna(df.race.mode(), inplace=True)

df['goal'].fillna(df.goal.mode(), inplace=True)

df['date'].fillna(df.date.mode(), inplace=True)

df['go_out'].fillna(df.go_out.mode(), inplace=True)

df['career_c'].fillna(df.career_c.mode(), inplace=True)

方法4: 我的方法變得越來越手動過程,最后這一個工程:

df['race'].fillna(2.0, inplace=True)

df['goal'].fillna(1.0, inplace=True)

df['date'].fillna(6.0, inplace=True)

df['go_out'].fillna(2.0, inplace=True)

df['career_c'].fillna(2.0, inplace=True)

+0

你是否看了替代方法? http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html –

+0

“方法2”有什么問題? –

+0

@MaxU方法2正在返回一個錯誤。 'mode'返回一個Series,而不是一個單一的值。 –

總結

以上是生活随笔為你收集整理的python的out模式_如何用python中的DataFrame列的模式替换NA值?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。