jeudi 11 février 2021

how to use for loop for such a functions?

How can I shorten the code using "for" loop. I am just not able to use for for this function.

def f(year):
    
        if year==2017:
            plt.bar(["NA_Sales","JP_Sales","EU_Sales","Other_Sales"],abc.iloc[0,1:5])
    
        elif year==2016:
             plt.bar(["NA_Sales","JP_Sales","EU_Sales","Other_Sales"],abc.iloc[1,1:5])
        elif year==2015:
             plt.bar(["NA_Sales","JP_Sales","EU_Sales","Other_Sales"],abc.iloc[2,1:5])
        elif year==2014:
             plt.bar(["NA_Sales","JP_Sales","EU_Sales","Other_Sales"],abc.iloc[3,1:5])
        elif year==2013:
             plt.bar(["NA_Sales","JP_Sales","EU_Sales","Other_Sales"],abc.iloc[4,1:5])
        elif year==2012:
             plt.bar(["NA_Sales","JP_Sales","EU_Sales","Other_Sales"],abc.iloc[5,1:5])
        elif year==2011:
             plt.bar(["NA_Sales","JP_Sales","EU_Sales","Other_Sales"],abc.iloc[6,1:5])
        elif year==2010:
             plt.bar(["NA_Sales","JP_Sales","EU_Sales","Other_Sales"],abc.iloc[7,1:5])

Aucun commentaire:

Enregistrer un commentaire