0

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?

1 Answer 1

2

You could do something like this:

def get_feature(df, cols=None):
    if cols is None:
        cols = df.columns
    . . . 
    . . .
    return features
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.