jeudi 9 septembre 2021

Make custom function with if-statement

I'm tring to make function with if statement. I want to change whichever df that is longer to sample to the other shorter df's length. But it doesn't work, throwing an error 'list index out of range'. Also, is there any better way to make this function instead of fitting another custom function within a custom function??

def apple(df, df2):

    if len(df) >= len(df2):
        df = df.sample(len(df2))
    else:
        df2 = df2.sample(len(df))
        
    plt.hist(df.iloc[:,1])
    plt.hist(df2.iloc[:,1])
    plt.show()

   def good(df, df2)
    one = np.histogram(df['apple1'])[0]
    two = np.histogram(df2['apple'])[0]
    return sum(one, two)

Aucun commentaire:

Enregistrer un commentaire