Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print row x without knowing the index in pandas

Tags:

python

pandas

I have a Dataframe with 45 columns and 11k rows. This dataframe consist of players. Columns displaying their name, player_id, rating, height etc. Pretend you have the name of a player in the dataframe, or their ID, and you want to access the entire row of that player. You want to see all the information of that individual, but you only have one unique identifyer.

I tried using df.loc[[id_number]], but that only takes me to the index of the dataframe, which does not correspond to player_id.

Hopefully I explained it well enough. If you have any questions, please post them below.

like image 783
Kenso33 Avatar asked Oct 14 '25 15:10

Kenso33


2 Answers

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

Related to https://stackoverflow.com/a/17071908/17487637

like image 55
Alex Casale Avatar answered Oct 17 '25 05:10

Alex Casale


You can try applying a mask:

df[df.playerId == id_number]

Assuming playerId is the name of the column containing the player ids.

like image 36
Learning is a mess Avatar answered Oct 17 '25 04:10

Learning is a mess



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!