0

I have following python function which takes query which is string as an input but instead of just passing simple string I would like pass it as regex...how can I do it. here query is string which contains alphabet/number/symbol for example "MSEB-1020-MSK-01" and "MSEB-102*-MSK-**"

def function(string: str):

    f_df = df_.loc[
        df_["Company"].str.contains(string)
    ]

1 Answer 1

1

Try this:

def function(df, string):

    f_df = df.loc[df["company"].str.contains(query, regex=True)] # `regex = True`, allows you to pass regex expresion

    return f_df  

df_query = function(df_benchmark, "whatever_your_regex_is")

hope this works for you

Sign up to request clarification or add additional context in comments.

2 Comments

The explanation police want to know your location
that was a funny comment, you could answer and help us both, haha i am not an expert at pandas, i am still learning , and answering questions helps, but sure here is my address 127.0.0.1

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.