0

Help!

df = df[df.groupby('id')['metric'].transform('max')==df['metric]]

and now my other functions don't work. I tried

df.reset_index(drop = True, inplace=True)...... #nope!

I tried to start from the very beginning - import libraries and re-read csv's and nope!

what happened?

df['d_d_Mean'] = df[df.groupby('id')['drugs'].transform('max')==df['drugs']]

Error:

<ipython-input-607-85fda50bf5a4>:12: 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: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
mcrute
  • 1,592
  • 1
  • 16
  • 27
  • Okay, this is not an error! This just a warning. It is warning of behavior that you probably really don't are about anyway. The easiest way to eliminate this "warning" is to add .copy on the end of your reassignment like this: `df['d_d_Mean'] = df[df.groupby('id')['drugs'].transform('max')==df['drugs']].copy()` – Scott Boston Sep 23 '20 at 15:21
  • To understand more about 'SettingWithCopy' warning look at this post: https://stackoverflow.com/q/20625582/6361531 – Scott Boston Sep 23 '20 at 15:22
  • df.sort_values(by='gen_rate', ascending=False).to_csv(os.path.join('dkp.csv')) I also used this code and all is well. I got my max values and my csv created. I will used the copy in the next go round. – query_weary Sep 23 '20 at 21:02

0 Answers0