Panda's Setting With Copy Warning question

Asked 6 days ago, Updated 6 days ago, 1 views

# Skip the top part
m = dom_int_skd.ETD < dom_int_skd.STD
dom_int_skd['DLA'] = dom_int_skd.ETD[m] + timedelta(1) - dom_int_skd.STD
dom_int_skd.DLA.fillna(dom_int_skd.ETD - dom_int_skd.STD, inplace=True)

# the problematic part
dom_int_skd.DLA[dom_int_skd.DLA < pd.Timedelta(30, 'minutes')] = pd.Timedelta(0, 'minutes')

If there is a place in the data frame dom_int_skd where the time delta value in the column 'DLA' is less than 30 minutes, I want to treat that part so that the time delta value is zero.

So I made the code as above. SettingWithCopyWarning: It says A value is trying to be set on a copy of a slice from a DataFrame.

I searched "dom_int_skd.DLA[dom_int_skd.DLA<pd.Timedelta(30, 'minutes')]"It seems to recognize this part as derived from a data frame, and if I modify it, I don't know if I need to modify the original, so I checked that I get a warning."

Did I get it right? I want to find a value that meets the conditions (less than 30 minutes) among the original data and modify the original data, what should I do?

python pandas

2022-09-20 16:03

1 Answers

dom_int_skd.loc[dom_int_skd.DLA < pd.Timedelta(30, 'minutes'), "DLA"] = pd.Timedelta(0, 'minutes')

You want to try it like this way.

2022-09-20 16:03

If you have any answers or tips

© 2022 pinfo. All rights reserved.