【发布时间】:2018-12-12 23:26:03
【问题描述】:
我有一个包含 custid、交易日期列等的销售表。我在 custid 列上使用 groupby,然后使用 agg 方法获取最大日期(获取该特定客户的最新交易日期)和最小日期(获取他在商店交易的第一个日期)。
我的代码如下:
sales['transdate'] = pd.to_datetime(sales['transdate']) # Converting the transdate column from string to timestamps.
sales['custid'].groupby.transdate({'count': np.count_nonzero ,'first': np.min, 'last' : np.max})
我想知道是否可以
使用 np.min/max 方法计算日期之间的最小值和最大值。 还是我应该使用其他一些与日期时间相关的方法?
【问题讨论】:
标签: python pandas numpy time-series pandas-groupby