Python 如何动态使用datetime对象?

Python 如何动态使用datetime对象?,python,pandas,datetime,Python,Pandas,Datetime,给定只有一列的数据帧df(由可重复的日期时间值组成)。e、 g: 日期 2017-09-17 2017-09-17 2017-09-22 2017-11-04 2017-11-15 你可以做: (df['date'].dt.to_period('M') # change date to Month .value_counts() # count the Month .reset_index(name

给定只有一列的数据帧
df
(由可重复的日期时间值组成)。e、 g:

日期 2017-09-17 2017-09-17 2017-09-22 2017-11-04 2017-11-15 你可以做:

(df['date'].dt.to_period('M')               # change date to Month
       .value_counts()                      # count the Month
       .reset_index(name='observations')    # make dataframe
)
你可以做:

(df['date'].dt.to_period('M')               # change date to Month
       .value_counts()                      # count the Month
       .reset_index(name='observations')    # make dataframe
)

我从来不知道
reset\u index()
有一个
name
参数。这是新的吗?@rhug123我知道,熊猫身上的东西太多了。自从我开始使用Pandas(我想是0.24)以来,它就一直存在。我从来不知道
reset\u index()
有一个
name
参数。这是新的吗?@rhug123我知道,熊猫身上的东西太多了。自从我开始使用熊猫(我想是0.24)以来,它就一直存在。