Im working with a column named "NACIMIENTO" that has a birthdate as "8 de enero de 1987". I need the month to be a number: "enero(january) =1" to put it on the column "MESNACIMIENTO".
I based the code on the function df.loc(condition) and added df["name column"] to asign the value to the column on that location only if condition is satisfied.
df["NACIMIENTO"]=df["NACIMIENTO"].apply(lambda x: x.lower())
df["MESNACIMIENTO"]=0
df["MESNACIMIENTO"].loc[df["NACIMIENTO"].str.contains("")==True]=1
df["MESNACIMIENTO"].loc[df["NACIMIENTO"].str.contains("febrero")==True]=2
df["MESNACIMIENTO"].loc[df["NACIMIENTO"].str.contains("marzo")==True]=3
... and so on for the rest of the months.
I expect the output to be a column with the month number, but I get: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame