Alasdair
Alasdair

Reputation: 1

Select row from a DataFrame based on values in a column in pandas

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

selects data from a row or rows in a dataframe given the specified column.

What is the equivalent if I need to specify the 'row name' ?

Upvotes: 0

Views: 295

Answers (1)

Andrew L
Andrew L

Reputation: 7038

If I understand correctly, you can pass the index directly to loc:

Example:

df

       a   b
group       
abc    6   9
abc    3  12
abc    5  56
def    8  32
gfd    4  65
uio    2  87
def    1  31
poi    8   2
fgb    3   3

df.loc['abc']
       a   b
group       
abc    6   9
abc    3  12
abc    5  56

Upvotes: 1

Related Questions