0

this is my code: my dataframe DF is based on this: index int64 FiscalYear int64 GL object GLID int64 GL_Debit float64 GL_Credit float64 month object Solde de fin float64

DF.sort_values(by=['GL', 'month'], inplace=True)
                    DF['Variation des périodes'] = DF.groupby([ 'GL'])['Solde de fin'].diff().fillna(DF['Solde de fin'])
                    DF = DF.rename(columns={'GL_Debit':'Débit année à date','GL_Credit':'Crédit année à date'})
            
for i in range(len(DF)):
                row = DF.iloc[i]
                teste = row['month'][5:7]
                if row['month'][5:7]=='04':
                    if row['GL'][0] in ['4', '5', '6', '7', '8', '9']:
                        DF.iloc[i]['Variation des périodes'] = row['Solde de fin']
                    else:
                        DF.iloc[i]['Variation des périodes'] = row['Variation des périodes']

I've this error: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame DF.iloc[i]['Variation des périodes'] = row['Solde de fin']

and

DF.iloc[i]['Variation des périodes'] does not show me row['Solde de fin']

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Have a look at this [question](https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas) and at [pandas docs](https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html). – Ric S May 21 '21 at 15:41

1 Answers1

0

I find a solution: replace bloc by loc and do not have warning and values are god!

DF.loc[i, 'Variation des périodes'] =row['Solde de fin']