Why did adding inplace='true' raise an error when used keep='first' was used along the code?

Screen Link:
https://app.dataquest.io/m/467/communicating-results/4/removing-duplicates

My Code:

paid = paid.sort_values(by=['Reviews'], ascending=False)
paid = paid.drop_duplicates(subset=['App'], keep='first')
print(paid.duplicated('App').sum())
paid = paid.reset_index(inplace=True, drop=True)

What I expected to happen:
Without the inplace=true, it had worked already. After looking at the answer, i saw that DQ used a lot of inplace=True and thought I would try it and see how it would change my dataframe.

What actually happened:

paid is a NoneType, but we expected it to be a DataFrame.

What happened?? Is it because I used keep=‘first’?? Like, do i have to use one or the other??

1 Like

Hello @jadelynwatling, Welcome to the DataQuest Community.!!

When using inplace=True don’t assign it to a variable since you are making the changes inplace.

Your code should be as follows
paid = paid.sort_values(by=['Reviews'], ascending=False)
paid = paid.drop_duplicates(subset=['App'], keep='first')
print(paid.duplicated('App').sum())
paid.reset_index(inplace=True, drop=True)
2 Likes

Thank you!

So, I didn’t need to assign it back to a variable, because if I pass the parameter of inplace=True, then it’s already going to do that… THANK YOU, It worked and I understand now.

paid.reset_index(inplace=True, drop=True)