'Datetime with only month and year

Let's say i have a dataframe, x, where my columns names are strings like this:

print(x.columns)
Index(['01/01/2014', '02/01/2014', '03/01/2014', '04/01/2014', '05/01/2014',
       '06/01/2014', '07/01/2014', '08/01/2014', '09/01/2014', '10/01/2014',
       ...
       '22/10/2016', '23/10/2016', '24/10/2016', '25/10/2016', '26/10/2016',
       '27/10/2016', '28/10/2016', '29/10/2016', '30/10/2016', '31/10/2016'],
      dtype='object', length=1034)

I need to convert those daily to monthly data, so i did the following:

x.columns = pd.to_datetime(x.columns, dayfirst=True, format='%d/%m/%Y')
monthly = x.resample('M', axis=1).sum()

But at each month, i still get this:

print(monthly.columns)
DatetimeIndex(['2014-01-31', '2014-02-28', '2014-03-31', '2014-04-30',
               '2014-05-31', '2014-06-30', '2014-07-31', '2014-08-31',
               '2014-09-30', '2014-10-31', '2014-11-30', '2014-12-31',
               '2015-01-31', '2015-02-28', '2015-03-31', '2015-04-30',
               '2015-05-31', '2015-06-30', '2015-07-31', '2015-08-31',
               '2015-09-30', '2015-10-31', '2015-11-30', '2015-12-31',
               '2016-01-31', '2016-02-29', '2016-03-31', '2016-04-30',
               '2016-05-31', '2016-06-30', '2016-07-31', '2016-08-31',
               '2016-09-30', '2016-10-31'],
              dtype='datetime64[ns]', freq='M')

But i need those columns in the format month/year. Another thing to note, when i try to plot my data i even get the hours:minutes:seconds in it, like this:

picture

Any help here? I just need those columns name to be in the format month/year.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source