samedi 13 février 2021

How to avoid using if elif loop for plotting graph for dataframe below as data frame consists of may rows

def f(genre):
    

    if genre=="Action":
        plt.bar(df2.Name[:5], df2.Global_Sales[:5])
        
    elif genre=="Adventure":
        plt.bar(df2.Name[5:10], df2.Global_Sales[5:10])
 

enter image description here How do you shorten the code as dataframe cosnsist of many rows and I want to avoid using if ,elif for thee data frame

Aucun commentaire:

Enregistrer un commentaire