Claudio Pierard
Claudio Pierard

Reputation: 179

Select rows with repeated string label in a column of a dataframe in pandas

I have this kind of data:

   element  wavelength  rel. int
0    N III      400.358     200.0
7     N II      403.508     360.0
8     N II      404.131     550.0
9     N II      404.353     360.0
12    N IV      405.776     150.0
14   N III      409.733     250.0
16     N I      409.994     140.0
19   N III      410.343     200.0
25     N I      410.995     185.0
60    N II      417.616     285.0
61   N III      419.576     120.0
62   N III      420.010     150.0
64    N II      422.774     285.0
67    N II      423.691     285.0
68    N II      423.705     220.0
69    N II      424.178     450.0
88   N III      433.291      90.0
93   N III      434.568     120.0
100  N III      437.911     300.0
114   N II      443.274     285.0
122   N II      444.703     650.0
141  N III      451.091      90.0
144  N III      451.486     120.0

I want to select only the rows with 'N II' in the 'element' column. What is a way of doing this?

I tried something with df.loc['N II'] but it doesn't work. I couldn't find a question that asked this, sorry if I repeated an existing question.

Thanks!

Upvotes: 0

Views: 39

Answers (1)

codebrotherone
codebrotherone

Reputation: 581

df[df.element == 'N II']

or

df.loc[df.element == 'N II']

or

df[df['element'] == 'N II']

Upvotes: 1

Related Questions