Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I go about selecting column data in a dataframe for specific row values in python?

As the question says, I have a data frame which is quite large but looks like:

        ID    Count    ValueX    Value 2    Value 3
RowX    1      234.     255.       yes.      yes
RowY    1      123.     135.       543.      342
RowW    1      234.     235.       yes.      yes
RowJ    1      123.     115.       543.      342
RowA    1      234.     285.       yes.      yes
RowR    1      123.     165.       543.      342
RowX    2      234.     255.       yes.      yes
RowY    2      123.     135.       543.      342
RowW    2      234.     235.       yes.      yes
RowJ    2      123.     115.       543.      342
RowA    2      234.     285.       yes.      yes
RowR    2      123.     165.       543.      342
.
.
.
RowX    1233   234.     255.       yes.      yes
RowY    1233   123.     135.       543.      342
RowW    1233   234.     235.       yes.      yes
RowJ    1233   123.     115.       543.      342
RowA    1233   234.     285.       yes.      yes
RowR    1233   123.     165.       543.      342

What I want is to be able to select all the values in column ValueX where the row is RowX for each of the ID numbers 1-1233 and return them in a list.

like image 240
tushariyer Avatar asked Apr 25 '26 12:04

tushariyer


1 Answers

df.query('1 <= ID <= 1233').loc['RowX', 'ValueX']

RowX    255.0
RowX    255.0
RowX    255.0
Name: ValueX, dtype: float64
like image 65
piRSquared Avatar answered Apr 27 '26 01:04

piRSquared