2017-08-05 51 views
1

所以我想做個好人,再這樣寫:分配()需要1周位置的說法,但2給予(SettingWithCopyWarning)

df1["Cum Correct"] = df1.groupby(level=0)["Correct"].cumsum() 

從而引發過度熱心SettingWithCopyWarning與此:

tmp={'Cum Correct': df1.groupby(level=0)["Correct"].cumsum()} 
df1= df1.assign(tmp) 

作爲基於我讀取使用assign是正確的方法。然而,這給我的錯誤:

TypeError: assign() takes 1 positional argument but 2 were given 

回答

3

嘗試解開tmp字典:

df1= df1.assign(**tmp) 
相關問題