-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: replace method for more time-related type #36592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
pls show exactly what you mean replace is a Timestamp method (inherited from datetime.datetime) and a Series / index method |
>>>pd.Timestamp('20200101').replace(day=5)
Timestamp('2020-01-05 00:00:00') Here replace change the day to 5. >>>ts = pd.date_range('20200101','20200501',freq='MS').to_series()
>>>ts
2020-01-01 2020-01-01
2020-02-01 2020-02-01
2020-03-01 2020-03-01
2020-04-01 2020-04-01
2020-05-01 2020-05-01
Freq: MS, dtype: datetime64[ns] I want to get this after use >>>ts.replace(day=5)
2020-01-01 2020-01-05
2020-02-01 2020-02-05
2020-03-01 2020-03-05
2020-04-01 2020-04-05
2020-05-01 2020-05-05
Freq: MS, dtype: datetime64[ns] Equal to >>>pd.date_range('20200101','20200501',freq='MS')
DatetimeIndex(['2020-01-01', '2020-02-01', '2020-03-01', '2020-04-01',
'2020-05-01'],
dtype='datetime64[ns]', freq='MS')
>>>pd.date_range('20200101','20200501',freq='MS').replace(day=5)
DatetimeIndex(['2020-01-05', '2020-02-05', '2020-03-05', '2020-04-05',
'2020-05-05'],
dtype='datetime64[ns]', freq='MS') Also for the index type. |
try .dt.replace |
>>>pd.date_range('20200101','20200501',freq='MS').to_series().dt.replace(day=5)
AttributeError: 'DatetimeProperties' object has no attribute 'replace' this raises error |
ok i suppose though to be honest .replace is not very useful and has a lot of tz implications much better to simply use offsets |
I see. But since in here DateOffset arguments that do not end in s is suggested to be deprecated in the future, how to do this ( We do this by |
Is this still under discussion? I would also find this method very helpful. |
Now we can only implement
replace
onTimestamp
, I thinkTimedeltaIndex
,Timedelta
,DatetimeIndex
and even Series withdatetime64[ns]
ortimedelta64[ns]
all needreplace
method (works like replace on Timestamp). Is there any plan to do this? (Maybe in pandas 2.0) Thanks!The text was updated successfully, but these errors were encountered: