moralmar
1/2/2018 - 3:31 PM

lambda 1

  • lambda

  • 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.

Source: Applied Data Science with Python - 01 Introduction

def answer_ten():
    Top15 = answer_one()
    
    med = Top15['% Renewable'].median()
    Top15['HighRenew'] = Top15['% Renewable']>=med
    
    Top15['HighRenew'] = Top15['HighRenew'].apply(lambda x:1 if x else 0)
    Top15.sort_values(by='Rank', inplace=True)
    return Top15['HighRenew']