jake wong jake wong - 3 months ago 14
Python Question

How to filter and print entire row via index in pandas

I"m having some issues in trying to print out just the rows based on the

index values


>>>in: print(df) # My table when I print df

>>>out:
Item Column1 Column2 Column3 Column4 Column5
Fooooo 64.318 7.574 0.471 0.364 -
Yooooo 56.839 7.252 (1.914) (1.945) (0.015)
Zaaaaa 45.275 7.186 (7.109) (1.611) (0.016)
Zorrrr 0.381 0.063 (5.305) (1.6) (0.017)
Kaarrr 1.325 0.26 (5.514) (2.563) (0.019)


Desired results

How do I separate the
df
via
index
such that it produces the results below?

>>>in: print(df index['Fooooo']) # For example
>>>out:
Item Column1 Column2 Column3 Column4 Column5
Fooooo 64.318 7.574 0.471 0.364 -

>>>in: print(df index['Yooooo']) # For example
>>>out:
Item Column1 Column2 Column3 Column4 Column5
Yooooo 56.839 7.252 (1.914) (1.945) (0.015)

>>>in: print(df index['Zaaaaa']) # For example
>>>out:
Item Column1 Column2 Column3 Column4 Column5
Zaaaaa 45.275 7.186 (7.109) (1.611) (0.016)


I have tried

print(df.index[0])
- This just gives me the
Item
. Does not come along with the rest of the
Columns

Answer

Try filtering method:

df[df.index == 'Fooooo']

          Column1  Column2 Column3 Column4 Column5
Item                                            
Fooooo   64.318    7.574   0.471   0.364       -
Comments