這是我的資料:

我怎樣才能得到所有帶有字串的列的平均值_var,如果這些列都沒有缺失值NaN?
uj5u.com熱心網友回復:
你可以只使用mean()with skipna=False。
# extract the columns based on prefix
cols = [col for col in df.columns.tolist() if col.startswith('_var')]
df['special_mean'] = df[cols].mean(skipna=False, axis=1)
# or using @sammywemmy's method
df['special_mean'] = df.filter(like='_var').mean(skipna=False, axis=1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/341432.html
上一篇:從randint回圈中獲取總和
下一篇:pythonid()函式實作
