0

if I have a dataframe with several row and several columns.

x = {a: (1,2,3),
     b: (4,5,6),
     c: (7,8,9)}
pd.DataFrame(x)

it will give out

    a   b   c
0   1   4   7
1   2   5   8
2   3   6   9

I want to extract the row where the value in column c is specific number

in this case, if the specific number is 8, I need the row 1.

1   2   5   8
EdChum
  • 376,765
  • 198
  • 813
  • 562
Liming Zhu
  • 221
  • 1
  • 3
  • 6

1 Answers1

1

Try this, it works:

df[df['c'] == 8]

Explanation: df['c'] == 8 produces a boolean mask where the condition is true, then df[] selects only them.

hacker315
  • 1,996
  • 2
  • 13
  • 23