0

I want to add a column( Stocks Needed) to the dataframe based on the condition below:

However, there is an error that appears at the else statement ( ^ SyntaxError: invalid syntax)

Any help, please?

condition = df1['Stocks'] > df1['Stocks for 7 days']

if condition:
  df1['Needed Stock'] = 0
  else: 
      df1['Needed Stock'] = df1['Stock for 7 days'].sub(df1['Stocks'], fill_value=0)
  • Use `df1['Needed Stock'] = np.where(condition, 0, df1['Stock for 7 days'].sub(df1['Stocks'], fill_value=0))` – jezrael Dec 08 '21 at 13:05

0 Answers0