How can I retrieve a row by index value from a Pandas DataFrame?

Viewed 37209

I have created a dataframe and set an index:

df = pd.DataFrame(np.random.randn(8, 4),columns=['A', 'B', 'C', 'D'])
df = df.set_index('A')

The dataframe looks like this:

                  B         C         D
A
 0.687263 -1.700568  0.140175  1.420394
-0.212621 -0.700442 -0.041497 -1.034021
-0.614214 -0.437313 -0.464493 -1.182492
-0.885062  0.203892 -0.412400 -0.578346
-1.222661  2.014908 -0.463674 -0.378910
 0.132472 -0.389512  0.623531 -0.788556
-1.083620  1.167158 -0.558217 -0.222078
 1.066270 -0.215586 -0.884757 -0.878557

How do I get the value of B in the row for which A is 0.687263?

I've tried:

e = df.loc(0.687263)

This gives me a LocIndexer object, rather than the row I'd expect (also I'd like to specify that it should be a single row if possible):

<pandas.core.indexing._LocIndexer object at 0x10385e210>

And if I now try e['B'] I get an error.

How do I get the value of B?

1 Answers
Related