0

I have the following code:

    self.filtered_rwr = self.rwr[self.rwr['type'].str.contains('Process')]

    self.filtered_rwr.insert(0, 'Session', 0)
    self.filtered_rwr.loc[:, 'Session'] = self.session_title

In which self.rwr is a dataframe.

My problem is i get a SettingWithCopyWarning on this action when:

  1. i have no use for self.rwr so i don't care about changing it
  2. i am using the .loc as instructed on a column which does not exist in the original.

i would prefer to solve the warning, but stop it from popping is also a plausible solution.

Suggestions? Thx

Guy Barash
  • 470
  • 5
  • 17
  • `loc` will not magically solve your problem. The problems happens before that. You are creating a copy and working on that copy, that's why it's called `SettingWithCopyWarning`. Change this line to: `self.filtered_rwr = self.rwr[self.rwr['type'].str.contains('Process')].copy()` and it should solve your problem – Erfan Oct 07 '20 at 13:17
  • Thx. But my self.rwr is HUGE, won't it take a long time? assuming i have no need for it anymore, can i skip the copy? just severe the link between them? – Guy Barash Oct 07 '20 at 13:22
  • 1
    You can also surpress the warning: https://stackoverflow.com/a/20644369/9081267 – Erfan Oct 07 '20 at 13:23

0 Answers0