-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Closed
Description
Related #21684
update: use set_axis.
import pandas as pd
dates=[
"2001-01-01 23:50",
"2001-01-02 14:00",
"2001-01-03 00:08"]
ser=pd.Series(range(3),pd.DatetimeIndex(dates))sometimes when writing a sequence of operation, you want to replace the index of the object you're working on. Say, quantizing the dates. I can't find the .method way of doing
ser.index= expr
So that I can't write something like
(ser
.replace_index(ser.index.floor("D")) # < this doesn't exist
.rolling("5d")
.sum()
Things that don't solve this:
reindexis aligning, so if your new index permutes the indexes, it isn't suitable.set_indextakes a column name, not an expression, and isn't available on series. update works for frames, though you must provide an arraylike, not a listlike.reindex_likeexpects a PandasObject instead of a listlike, and is aligningreset_indexdoes not take a values argument
In [1]: [_ for _ in dir(ser) if 'index' in _ and not _.startswith("_")]
Out [1]:
['first_valid_index',
'index',
'last_valid_index',
'reindex',
'reindex_axis',
'reindex_like',
'reset_index',
'sort_index']
Metadata
Metadata
Assignees
Labels
No labels