Selecting rows of a dataframe based on value/string pattern in a column

Comparing a string pattern with values in a column of a pandas DataFrame.

Many times i have seen that,

x_df.loc[x_df.column_A == "xyz",:] fails to return the rows which contain "xyz" in the column_A of Data Frame x_df

Its always better to use below code for this task of selecting rows where column_A has "xyz" as its value,

x_df[x_df['column_A'].str.contains("xyz")]

Comments

Popular posts from this blog