Skip to content

pd.groupby(pd.TimeGrouper('W')).groups returns Timestamps instead of Periods #15141

Closed
@jimbasquiat

Description

@jimbasquiat

Lets consider the following DataFrame:

date_range = pd.date_range(dt(2010,1,1), dt(2010,1,31), freq='1D')
df = pd.DataFrame(data = np.random.rand(len(date_range),2), index = date_range)

If I group the datapoints by periods of 1 week and visualize the groups definition, I get:

In: [1]:df.groupby(pd.TimeGrouper('W')).groups
Out:[1]: 
     {Timestamp('2010-01-03 00:00:00', freq='W-SUN'): 3,
     Timestamp('2010-01-10 00:00:00', freq='W-SUN'): 10,
     Timestamp('2010-01-17 00:00:00', freq='W-SUN'): 17,
     Timestamp('2010-01-24 00:00:00', freq='W-SUN'): 24,
     Timestamp('2010-01-31 00:00:00', freq='W-SUN'): 31}
I retrieve the keys of that dictionary:

In: [2]: list(df.groupby(pd.TimeGrouper('W')).keys())
Out:[2]: 
    [Timestamp('2010-01-03 00:00:00', freq='W-SUN'),
     Timestamp('2010-01-10 00:00:00', freq='W-SUN'),
     Timestamp('2010-01-31 00:00:00', freq='W-SUN'),
     Timestamp('2010-01-17 00:00:00', freq='W-SUN'),
     Timestamp('2010-01-24 00:00:00', freq='W-SUN')]

However I am left with those funny variables such as Timestamp('2010-01-24 00:00:00', freq='W-SUN') that have the prefix Timestamp but are structured like Periods. I think this is not correct, and those variables should be Periods?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions