1

From the sample dataset 'iris', i have created a dataframe df as follows :

import seaborn as sns
df = sns.load_dataset('iris')

From this i created another dataframe d2 & from the '_is_view' flag, i can see that the d2 is created as a copy (rather than a view). Since d2 is created as a copy, any operations on it (say dropping a column as shown in screenshot below) should not result in SettingWithCopyWarning. But still i am getting the warnings as shown below. Can anyone please let me know why i am seeing the warnings 1) in case of dropping a column 2) in case of modifying a column. If d2 was a view rather than copy, then these warnings are expected as it may result in modifying the df. But not sure why it is so in case of copy. enter image description here

mezda
  • 3,537
  • 6
  • 30
  • 37
  • 1) If you plan to modify stuff, why not copy: `d2 = df[df.species=='setosa'].copy()`. 2) Don't use `inplace`: `d2 = df[df['species']=='setosa'].drop(range(6,49))`. – Quang Hoang Feb 09 '23 at 04:02
  • 1
    also a search for `_is_view`: https://stackoverflow.com/questions/39101933/pandas-views-vs-copy-the-docs-says-nobody-knows. – Quang Hoang Feb 09 '23 at 04:03
  • @QuangHoang : Thanks for your reply. Yes, i can use copy to avoid the warning. But what i wanted to know is why the warning is issued even though its making a copy by default. Also you told not to use "inplace", can you please let me know what is the issue in using "inplace" ? – mezda Feb 09 '23 at 06:33

0 Answers0