For a column in my dataframe I am trying to replace strings to integers.
There are only two string in the column named Indicators. for ex : "A","B"
I want all "A" in the column to be set to 1. All "B" in the column be set to 0.
Tried two methods however both gives me "A value is trying to be set on a copy" Error
method 1:
df["Indicators"] = df["Indicators"].replace("A", 1)
df["Indicators"] = df["Indicators"].replace("B", 2)
outputs what I want but gives me an error. Also is there a way to put these into one line of code?
method 2:
indicators = {"A":1, "B":2}
df["Indicators"] = df["Indicators"].apply(indicators.get).astype(float)
This gives me the same thing.