如何根据日期条件从多索引中删除特定列 [英] 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)
数据透视表之前的数据框
所需的输出
请注意,输出基于当前月份
如果今天的日期> 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.
这篇关于如何根据日期条件从多索引中删除特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文