Reputation: 71
If I have a DataFrame indexed by datetimes, how can I select the rows corresponding to the first day of each month, or check if a given row is at the first day of a month?
Upvotes: 1
Views: 621
Reputation: 153550
Here is another way, use the is_month_start
attribute with boolean indexing:
df[df.index.is_month_start]
Technically, this should be the fastest way, since this is already an attribute of the DateTimeIndex.
Upvotes: 1
Reputation: 863741
Select all rows with first day by compare DatetimeIndex.day
in boolean indexing
:
df[df.index.day == 1]
Upvotes: 4