2024-04-25 03:54:50 发布
网友
我有一个数据集,我试图分解和统计每月发生的次数。我还需要转换最终结果,为每个月/每个事件添加一列
Report_ID Report_name timestamp 1 Profit 8/1/2018 06:10:40 2 Revenue 8/5/2018 09:25:45 1 Profit 8/29/2018 10:11:30 2 Revenue 9/1/2018 09:45:22
输出:
将pd.crosstab与dt访问器一起使用strftime:
pd.crosstab
strftime
pd.crosstab(df.Report_ID, df['timestamp'].dt.strftime('%m/%Y'))\ .reset_index()\ .rename_axis([None], axis=1)
将
pd.crosstab
与dt访问器一起使用strftime
:输出:
^{pr2}$相关问题 更多 >
编程相关推荐