ZhangZhihui's Blog  
print(df_year_month)
print('--------------------------------------------------')
print(df_year_month.index)
print(df_year_month.index.tolist())
print('--------------------------------------------------')
print(df_year_month.index.levels[0])
print(df_year_month.index.levels[0].tolist())
print('--------------------------------------------------')
print(df_year_month.index.get_level_values(0))
print(df_year_month.index.get_level_values(0).tolist())


            cnt
year month
2020 01      94
     02      95
     03     132
     04     167
     05     106
     06      81
     07      64
     08      99
     09      60
     10      97
     11      91
     12      89
2021 01     113
     02      85
     03     103
     04     115
     05     138
     06     141
     07     120
     08     108
     09     110
     10      95
     11      86
2022 01       7
--------------------------------------------------
MultiIndex([('2020', '01'),
            ('2020', '02'),
            ('2020', '03'),
            ('2020', '04'),
            ('2020', '05'),
            ('2020', '06'),
            ('2020', '07'),
            ('2020', '08'),
            ('2020', '09'),
            ('2020', '10'),
            ('2020', '11'),
            ('2020', '12'),
            ('2021', '01'),
            ('2021', '02'),
            ('2021', '03'),
            ('2021', '04'),
            ('2021', '05'),
            ('2021', '06'),
            ('2021', '07'),
            ('2021', '08'),
            ('2021', '09'),
            ('2021', '10'),
            ('2021', '11'),
            ('2022', '01')],
           names=['year', 'month'])
[('2020', '01'), ('2020', '02'), ('2020', '03'), ('2020', '04'), ('2020', '05'), ('2020', '06'), ('2020', '07'), ('2020', '08'), ('2020', '09'), ('2020', '10'), ('2020', '11'), ('2020', '12'), ('202
1', '01'), ('2021', '02'), ('2021', '03'), ('2021', '04'), ('2021', '05'), ('2021', '06'), ('2021', '07'), ('2021', '08'), ('2021', '09'), ('2021', '10'), ('2021', '11'), ('2022', '01')]
--------------------------------------------------
Index(['2020', '2021', '2022'], dtype='object', name='year')
['2020', '2021', '2022']
--------------------------------------------------
Index(['2020', '2020', '2020', '2020', '2020', '2020', '2020', '2020', '2020',
       '2020', '2020', '2020', '2021', '2021', '2021', '2021', '2021', '2021',
       '2021', '2021', '2021', '2021', '2021', '2022'],
      dtype='object', name='year')
['2020', '2020', '2020', '2020', '2020', '2020', '2020', '2020', '2020', '2020', '2020', '2020', '2021', '2021', '2021', '2021', '2021', '2021', '2021', '2021', '2021', '2021', '2021', '2022']

  

posted on 2022-01-07 22:12  ZhangZhihuiAAA  阅读(25)  评论(0编辑  收藏  举报