简体   繁体   English

筛选数据透视表的行

[英]Filtering the rows of a pivot table

I have generated this Pivot Table and would like to be able to select the country in which there are (Export & Import) entries for every month of the year 2014, where the period 201401 represents the month of January 2014, 201402 February 2014 etc. Obviously in this case it is only Ireland in this example but I would like to be able to do find it programmatically just in case I come across an instance where I cannot do it by sight. 我已经生成了此数据透视表,并希望能够选择2014年每个月的条目(导出和导入)所在的国家/地区,其中201401期代表2014年1月,201402年2014年2月等。显然,在这种情况下,本例中仅是爱尔兰,但是我希望能够以编程方式找到它,以防万一我遇到无法目睹的情况。 I have tried filtering and grouping techniques and using the len function but these are only applicable to the columns of a data frame and not the rows? 我尝试了过滤和分组技术并使用len函数,但是这些仅适用于数据框的列而不适用于行?

You can reset the index, so that you can manipulate them as columns. 您可以重置索引,以便可以将它们作为列进行操作。 For example, you could try: 例如,您可以尝试:

milk_keypartners_pivot6 = milk_keypartners_pivot6.reset_index()
groupedCount = (milk_keypartners_pivot6.groupby('Partner')['Trade Flow'].count() == 12)
countries_with_12 = groupedCount[groupedCount == True].index
milk_keypartners_pivot6 = milk_keypartners_pivot6[milk_keypartners_pivot6['Partner'].isin(countries_with_12)]

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

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