Select dataframe rows by specific column string values in Pandas

Hello, I’m back! 😎

Now the traditional method is this:

df.loc[df['column_name'] == value]

For string, and for numeric values this:

df.loc[df['column_name'] == 'string']

While it always work with numeric values, for string values sometimes it doesn’t work. It picks up a blank dataframe. I guess it’s something to do with encoding of the source where you got your data from in the first place. So to make it quick, here is an alternative method that worked for me:

df[df['column_name'].str.contains("string")]

There you go 🙃

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x