new_df = pd.concat(new_dataset)
print(new_df.shape)
new_df = new_df.dropna(how='any')
print(new_df.shape)
new_df.head(20)
Now I want to add another column naming 'Close_gap_IUD' on the basis of values from 'Close_gap' column. I want:
- 'Increase' label in 'Close_gap_IUD' column, for the positive values(>0) of 'Close_gap' column, 2. 'Decrease' label in 'Close_gap_IUD' column, for the negative values(<0) of 'Close_gap' column,
- 'Unchanged' label in 'Close_gap_IUD' column, for the zero values(==0) of 'Close_gap' column
How can I do this?
CodePudding user response:
new_df["Close_gap_IUD"] = new_df["Close_gap"].apply(lambda x: "Increase" if x > 0 else "Decrease" if x < 0 else "Unchanged")