1
我有這樣的一個表:如何創建蟒蛇(大熊貓)數據透視表
train_df:
Sex Target
M 1
M 1
M 1
F 0
F 1
F 0
我想創建一個數據透視表,以便它可以顯示結果有些事情是這樣的:
Row Labels Average of Target
F 0.333333333
M 1
我已經寫了這樣的代碼:
temp2 = train_df.pivot_table(values='Target', index=['Sex'],aggfunc=lambda x: x.map.mean().
我越來越像「AttributeError:」函數'object has no attribute'mean''出錯。我知道map.mean函數中的用法不正確。你能幫我解決這個問題嗎?謝謝。
'train_df.groupby( '性別',as_index = FALSE).Target.mean ()'爲什麼不呢? – Zero