meltdf = pd.melt(df, id_vars=['State', 'RegionName', 'RegionID', 'Metro',
    'CountyName', 'SizeRank'], var_name='Date', value_name='Data')
meltdf['Date'] = pd.to_datetime(meltdf['Date'] + '-01')
meltdf['YearQuarter'] = meltdf['Date'].dt.year.astype(str) + 'Q' + meltdf[
    'Date'].dt.quarter.astype(str)
pivotdf = pd.pivot_table(meltdf, index=['State', 'RegionName', 'RegionID',
    'Metro', 'CountyName', 'SizeRank'], columns=['YearQuarter'], values=
    'Data', aggfunc=np.mean)
pandas how to use groupby to group columns by date in the label?