Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

So I'm trying to be a good person and re-write this:

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

which triggers the over-zealous SettingWithCopyWarning with this:

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

as based on what I read using assign is the correct approach. However this gives me the error:

TypeError: assign() takes 1 positional argument but 2 were given
like image 222
user1761806 Avatar asked Oct 19 '25 05:10

user1761806


1 Answers

try to unpack the tmp dict:

df1= df1.assign(**tmp)
like image 119
MaxU - stop WAR against UA Avatar answered Oct 22 '25 04:10

MaxU - stop WAR against UA