1
na.rm我有以下數據:計算rowmeans忽略娜的大熊貓,像R中
a = pd.Series([1, 2, "NA"])
b = pd.Series(["NA", 2, 3])
df = pd.concat([a, b], axis=1)
# 0 1
# 0 1 NA
# 1 2 2
# 2 NA 3
現在,我想計算rowmeans像R中與na.rm=T
。
c.mean(skipna=True, axis=0)
# Series([], dtype: float64)
我期待:
# 0 1 # 1/1
# 1 2 # (2+2)/2
# 2 3 # 3/1
如何實現這一目標?
僅供參考:當只傳遞kwargs到''.apply''時,你可以直接執行:''df.apply(pd.to_numeric,errors ='force')。mean(axis = 1)'' – Jeff
@Jeff感謝您的提示,當函數將args作爲默認用法時,我傾向於使用'lambda's – EdChum