Skip to content Skip to sidebar Skip to footer

Grouping Date Index In Pandas

I have a dataframe looks like this: In [101]: import pandas as pd df = pd.DataFrame( {'date':['2014-06-30','2014-06-30','2014-06-29','2014-06-29','2014-06-29'], 'value':[1,2,5,

Solution 1:

df.set_index('date') needs to assigned to df and you coule use .loc

df = pd.DataFrame( {'date':['2014-06-30','2014-06-30','2014-06-29','2014-06-29','2014-06-29'], 'value':[1,2,5,5,4]})
df = df.set_index('date')
df

            value
date
2014-06-30      1
2014-06-30      2
2014-06-29      5
2014-06-29      5
2014-06-29      4

Use .loc

df.loc['2014-06-30']

            value
date
2014-06-30      1
2014-06-30      2

Post a Comment for "Grouping Date Index In Pandas"