I have 2 data frames named df and df_flags.
df = pd.read_excel('Check.xlsx')
df_flags = pd.DataFrame(index=df.index, columns=df.columns) # empty dataframe
I want to store flag values at resp. index in df_flag, whenever conditions mentioned below, gets satisfied. Following is my code.
for col in df_flags.columns :
df_flags.loc[(df[col].fillna(0) > 0 and df[col].fillna(0) <= 10), col] = 0
df_flags.loc[(df[col].fillna(0) > 25 and df[col].fillna(0) <= 50), col] = 0.5
df_flags.loc[(df[col].fillna(0) > 50 and df[col].fillna(0) <= 150), col] = 1
However I am getting an error described as below,
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I have used the following code snippet and it was working fine but it's giving a value error for 1st code snippet.
for col in df_flags.columns :
df_flags.loc[df[col].fillna(0) <= 0, col] = 1
df_flags.loc[df[col].fillna(0) == 0, col] = 2
df_flags.loc[df[col].fillna(0) > 200, col] = 3
Kindly suggest what I'm doing wrong or is there a better way to do it.