0

I am doing the following exercise and I have some part of it

Create a new column with a 1 if the country's % Renewable value is at or above the median for all countries in the top 15, and a 0 if the country's % Renewable value is below the median.

My code:

df = answer_one()
print(df)
mean = df['#% Renewable'].mean()
df['ratio'] = df['#% Renewable'] > mean 

I want to know if there is a way to create in one line a ternary operator, something like:

If renewable > mean then 0 if renewable < mean then 1.

but not sure how to achieve this on python in one line

Luis Valencia
  • 29,595
  • 84
  • 264
  • 467

0 Answers0