I have a pandas DataFrame. I would like to add a new column with a value of 1 for a new column, y, if the previous value of x is less than 50 and the current value is more than 50.
I get this error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
code:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(40,60,size=(10, 1)), columns=['x'])
df['y'] = 1 if (df['x'].shift(1) < 50) and (df['x'] > 50) else 0