'Subsetting a rows with specific data in a pandas series

I have a series, Data that has the following data:

timestamp                
02-12-2013 12:00:12        1.2
02-12-2013 14:00:00        1.4
02-13-2013 16:05:12        1.7 
02-15-2013 16:05:12        1.7 

I'm trying to subset the data by data[data.index == '02-12-2013'] and it only returns the first instance. May I know how can I obtain all rows that have the specified date?



Solution 1:[1]

Have you tried pandas.DataFrame?

import pandas as pd

aaa = ['02-12-2013', '02-12-2013', '02-13-2013', '02-15-2013']
bbb = ['12:00:12', '14:00:00', '16:05:12', '16:05:12']
ccc = [1.2, 1.4, 1.7, 1.7]

df=pd.DataFrame([bbb,ccc],columns=aaa)

The result will be:

df["02-12-2013"]

  02-12-2013 02-12-2013
0   12:00:12   14:00:00
1        1.2        1.4

If you want a row, just transpose it

df["02-12-2013"].T

                   0    1
02-12-2013  12:00:12  1.2
02-12-2013  14:00:00  1.4

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kevin Choon Liang Yew