0

I am counting the number of ratings per user in my book reviews dataframe, by using:

df_new['ratings_per_user']=df_new.groupby('userID')['userID'].transform('count')

this seems to work, but it throws an error (or rather, a warning):

/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  """Entry point for launching an IPython kernel.

I don't understand how I can rewrite the above command using .iloc, and, more generally, what the actual problem is.

Qubix
  • 4,161
  • 7
  • 36
  • 73
  • NO, it is not a duplicate ! The question you hint to, and which I found before posting, uses a condition before assigning the value to the new column. It is not at all the same as what I am asking. – Qubix Apr 23 '19 at 12:00
  • You need to show more of your code, more specific; how is `df_new` created? From the looks of it `df_new` is a copy of another dataframe, and therefore you get a warning since you are trying to modify a copy. – Cleared Apr 23 '19 at 12:09
  • we need to look at the definition/construction of `df_new`, but I do believe this is a duplicate – Yuca Apr 23 '19 at 12:56

0 Answers0