You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can set/change the name of a DatetimeIndex with .rename(). But I cannot set/change its frequency in the same manner.
Feature Description
To rename a DatetimeIndex, I can do this inplace with idx.name = 'foo'. Or I can get a new object with idx2 = idx.rename('foo').
I can set or change the frequency inplace with idx.freq = 'QS-APR', but an analogous method for setting or changing the frequency does not exist.
This proposal is to add the method DatetimeIndex.set_freq
Considering the method name: with_freq() or set_freq() would both work. I would not use as_freq() to avoid confusion with the existing methods Series.as_freq() and DataFrame.as_freq() which have a different functionality (i.e., change the index length).
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
I can set/change the name of a
DatetimeIndex
with.rename()
. But I cannot set/change its frequency in the same manner.Feature Description
To rename a
DatetimeIndex
, I can do this inplace withidx.name = 'foo'
. Or I can get a new object withidx2 = idx.rename('foo')
.I can set or change the frequency inplace with
idx.freq = 'QS-APR'
, but an analogous method for setting or changing the frequency does not exist.This proposal is to add the method
DatetimeIndex.set_freq
Considering the method name:
with_freq()
orset_freq()
would both work. I would not useas_freq()
to avoid confusion with the existing methodsSeries.as_freq()
andDataFrame.as_freq()
which have a different functionality (i.e., change the index length).The method body would be something like
I'm happy to create a PR for this if devs think this is a worthwhile addition
Alternative Solutions
I can keep on using
but that cannot be used in list comprehensions or lambda expressions and is not chainable, and looks more clunky.
If I need something chainable, the best I think I can do is
though that undeservedly raises an Exception if the frequencies are equivalent (e.g. QS-FEB and QS-MAY).
Additional Context
See also #61086
The text was updated successfully, but these errors were encountered: