我有一个“df”,它有一个多级索引(STK_ID,RPT_Date)
sales cogs net_pft
STK_ID RPT_Date
000876 20060331 NaN NaN NaN
20060630 857483000 729541000 67157200
20060930 1063590000 925140000 50807000
20061231 853960000 737660000 51574000
20070331 -2695245000 -2305078000 -167642500
20070630 1146245000 1050808000 113468500
20070930 1327970000 1204800000 84337000
20071231 1439140000 1331870000 53398000
20080331 -3135240000 -2798090000 -248054300
20080630 1932470000 1777010000 133756300
20080930 1873240000 1733660000 92099000
002254 20061231 -16169620000 -15332705000 -508333200
20070331 -763844000 -703460000 -1538000
20070630 501221000 289167000 118012200
20070930 460483000 274026000 95967000
如何编写一个命令来过滤“RPT_Date”包含“0630”的行(这是Q2报告)?结果应该是:
sales cogs net_pft
STK_ID RPT_Date
000876 20060630 857483000 729541000 67157200
20070630 1146245000 1050808000 113468500
20080630 1932470000 1777010000 133756300
002254 20070630 501221000 289167000 118012200
我正在尝试使用df[df['RPT_Date'].str.contains('0630')]
,但 Pandas 拒绝工作,因为'RPT_Date'
它不是列而是 sub_level 索引。
感谢您的提示...