4

I have a DataFrame like this:

col1,col2
Sam,NL
Man,NL-USA
ho,CA-CN

And I would like to select the rows whose second column contains the word 'NL', which is something like SQL like command. Does anybody know about a similar command in Python Pandas?

0

1 Answer 1

8

The answer is here. Let df be your DataFrame.

df[df['col2'].str.contains('NL')]

This will select all the records that contain 'NL'.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.