I am trying to replace all values in a pandas dataframe column df.column_A
if they fall within the range of 1 to 10.
However, when I do:
df.loc[(1 < df.column_A < 10), "Column_A"] = 1
Produces:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
Alternatively, when I do:
df.loc[(df.column_A < 10) & (df.column_A > 1), "df.column_A"] = 1
I am not getting an error at all, but the values don't get replaced.
What is strange is that when I do:
df.loc[(df.column_A < 10) | (df.column_A > 1), "df.column_A"] = 1
all values in df.column_A
get replaced with 1
, as I would expect.
This means that the syntax of the line is correct, so the mistake must be due to some factors I don't understand.
What am I doing wrong?