简体   繁体   English

如何根据日期条件从多索引中删除特定列

[英]How to remove specific columns from multi-index based on date condition

I need to drop the subcolumns from multiindex dataframe based on today's date我需要根据今天的日期从多索引数据框中删除子列

df = pd.pivot_table(df, index=['PC', 'Geo', 'Comp'], values=['Bill1', 'Bill2', Bill3], 
                        columns=['Month'], fill_value=0)


dataframe before pivot table数据透视表前的数据框

在此处输入图片说明


desired output期望的输出

please note that the output is based on current month请注意,输出基于当月
if today's date >15如果今天的日期 >15

今天的日期 >15

if today's date <15如果今天的日期 <15 今天的日期<15

You can modify your code as below.您可以修改您的代码,如下所示。

df.iloc[:,np.in1d(df.columns.get_level_values(1), [dat])]

Hope this will solve your problem.希望这能解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM