I have a DataFrame like this:
import pandas as pd
df = pd.DataFrame(columns=list('ABC'))
df[A] = [22, 43, 64, 86]
And, I want to populate the other two columns using comparison operators. Here is what I have:
if df['A'] <= 25:
df['B'] = 'k'
df['C'] = 'k'
elif df['A'] > 25 & df['A'] <= 50:
df['B'] = 'b'
df['C'] = 'none'
elif df['A'] > 50
df['B'] = 'g'
df['C'] = 'r'
But, I'm having trouble with using the operators on a DataFrame. I get an error like "ValueError: The truth value of a Series is ambiguous." Does anyone know a workaround?
Edit: I'd like to stick with using elif
due to the potential of very large DataFrames in the future. I'm trying to avoid searching through the DataFrame every time I use a new comparison operator.