0

I explain my problem to you. I have a data frame and I want to add a column (true / false). This dataframe contains the following columns: Référence, msn, description... I have another dataframe containing a reference called "AM" and other columns. The objective of filling this one column (true / false) if there is a correspondence between the two tables on the refe field. here is my python code:

df["Avis BE"]=False
df[df["Référence"].isin(df1["AM"])]["Avis BE"]=True

I have this error message: /usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead

Corralien
  • 109,409
  • 8
  • 28
  • 52
grinim
  • 113
  • 8
  • 1
    Maybe this post can help you. [How to deal with SettingWithCopyWarning in Pandas](https://stackoverflow.com/q/20625582/16936415) – Troll Oct 23 '21 at 14:59

1 Answers1

0

It's a warning, use

df.loc[:, "Avis BE"] = False
df.loc[df["Référence"].isin(df1["AM"]), "Avis BE"] = True

Also refer pandas documentation for indexing and setting values. it highlights this issue and suggesets better practices. Documentation

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Ajay Verma
  • 610
  • 2
  • 12