0

I would like to apply mutiply keyword filter for filtering down on columns.I tried this code:

df = df.filter(regex='AMP','amp','date') 

Error I get :

df = df.filter(regex='AMP','amp','date')
                                ^
SyntaxError: positional argument follows keyword argument.

Basically,I want all the columns with these keywords contained in their column name. Thank you in advance

2
  • error message says: never use positional erguments behind keyword arguments in python - simply because position is meaningless after an arbitrary list of kwargs is provided Commented May 11, 2018 at 7:11
  • basically df = df.filter('AMP','amp','date') Commented May 11, 2018 at 7:14

1 Answer 1

3

The regex has to be one valid regex string. You separated three strings by comma, so python interpreted the last two strings as separate arguments (without keyword). the proper 'or' - operator in regex is '|', so your desired filter would look like this:

df.filter(regex='AMP|amp|date')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! It worked!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.