lundi 7 novembre 2016

Consecutive if-conditions in function, Python

I am creating a function which calulates an outcome depending on parameters in the formula.

Separately to the first if-function I'd like to add a second condition for cases in which n is not None

def target_n(data, y, q = None, s = 1, n = None, ascending = True):
        if q is not None:
            target = quantile(data, q, s)
            return(target)
        else:
            target = y(data,s)
            return(target)
        if n is not None:
            sort = target.sort(tst.columns[0],ascending = ascending).ix[0:n,:]
        return(sort)

Nevertheless the function returns "target" and not "sort" for cases in which n is not None. How can I implement this?

Aucun commentaire:

Enregistrer un commentaire