Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting a specific row and column within pandas data array

Hopefully this is a quick and simple one. Having looked through the entirity of the pandas.DataFrame documentation I can't quite seem to find exactly what I need. I have a DataFrame as:

           StartDate          End Date
0   10/11/2014 00:00  10/12/2014 12:00
1   12/01/2015 08:00  31/01/2015 07:59
2   15/01/2015 00:00  19/02/2015 15:43

Say, for example, I want to access the value at StartDate column index value 2...i.e, 15/01/2015 00:00 how is this achieved?

like image 893
GCien Avatar asked Nov 22 '16 12:11

GCien


1 Answers

Use loc:

print (df.loc[2, 'StartDate'])
15/01/2015 00:00

or faster at:

print (df.at[2, 'StartDate'])
15/01/2015 00:00

In [199]: %timeit (df.loc[2, 'StartDate'])
10000 loops, best of 3: 147 µs per loop

In [200]: %timeit (df.at[2, 'StartDate'])
100000 loops, best of 3: 6.3 µs per loop
like image 137
jezrael Avatar answered Oct 05 '22 17:10

jezrael