Manish Kumar Singh
Manish Kumar Singh

Reputation: 411

Set default value of a function

I have to make a function which takes dataframe as one input and required columns as second input

def get_feature(df,cols=df.columns):
    . . .
    . . . 
    . . .
    return features

so here i want second parameter to be a list of columns which user can enter otherwise it should take all the columns of dataframe passed as parameter one as default, is there any way to do that?

Upvotes: 0

Views: 44

Answers (1)

Heike
Heike

Reputation: 24420

You could do something like this:

def get_feature(df, cols=None):
    if cols is None:
        cols = df.columns
    . . . 
    . . .
    return features

Upvotes: 2

Related Questions