How can I Group By Month from a Date field using Python/Pandas
问题 I have a Data-frame df which is as follows: | date | Revenue | |-----------|---------| | 6/2/2017 | 100 | | 5/23/2017 | 200 | | 5/20/2017 | 300 | | 6/22/2017 | 400 | | 6/21/2017 | 500 | I need to group the above data by month to get output as: | date | SUM(Revenue) | |------|--------------| | May | 500 | | June | 1000 | I tried this code but it did not work: df.groupby(month('date')).agg({'Revenue': 'sum'}) I want to only use Pandas or Numpy and no additional libraries 回答1: try this: In [6]: