Python Forum
Setting with copy warning
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting with copy warning
#4
You are getting the "setting with copy" warning because you are trying to assign a value to a subset of a DataFrame without using the .loc accessor. The .loc accessor is used to ensure that the original DataFrame is not modified in place.

To fix this, you should use the .loc accessor when assigning values to a subset of a DataFrame:

dfout.loc[:,3] = dfout.loc[:,0]
dfout.loc[:,4] = dfout.loc[:,1]
dfout.loc[:,5] = dfout.loc[:,2]
dfout.loc[:,6] = np.sqrt(dfout.loc[:,4]**2+dfout.loc[:,5]**2)
dfout.loc[:,7] = np.arctan(dfout.loc[:,5]/dfout.loc[:,4])/np.pi*360
Reply


Messages In This Thread
Setting with copy warning - by catlessness - Feb-13-2023, 02:07 PM
RE: Setting with copy warning - by catlessness - Feb-13-2023, 02:09 PM
RE: Setting with copy warning - by Vadanane - Feb-13-2023, 10:26 PM
RE: Setting with copy warning - by Vadanane - Feb-14-2023, 09:59 AM
RE: Setting with copy warning - by catlessness - Feb-14-2023, 10:59 AM
RE: Setting with copy warning - by deanhystad - Feb-21-2023, 12:58 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020