0

I'm trying to populate a simple numbered column on my pandas dataframe, for reference later. My for loop for doing that is as below:

for x in ((jac_input.index)/2):
    jac_output['Cycles'][x] = x+1

However, when running the script, I get this error:

SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

Why would my simple for loop cause this error? I'm just getting back into programming so I'm confused as to why this is happening, any help would be greatly appreciated.

  • There are 2 possibilities, prior issue with creating `jac_output` or the use of `jac_output['Cycles'][x]`. Better use `jac_output.loc[x, 'Cycles']`, if you still have the error, this is due to what you did prior to the shown code. – mozway Apr 13 '22 at 12:51

0 Answers0