简体   繁体   English

根据特定的行值选择熊猫数据透视表中的列?

[英]Selecting columns in a pandas pivot table based on specific row value?

I have data in a pivot table dataframe. 我在数据透视表数据框中有数据。 The columns are dates labeled 'UniqueDate' and the index is 'Time' of day. 列是标有“ UniqueDate”的日期,索引是“时间”。 I would like to select all columns where the 10th minute of the day is a positive value. 我想选择一天中第10分钟为正值的所有列。 Having some difficulty doing this due to the pivoted nature of the data. 由于数据的关键性,这样做有些困难。

UniqueDate  Apr 03, 2015  Apr 04, 2014  Apr 11, 2014  Apr 24, 2015
Time                                                              
00:00:00             NaN           NaN           NaN           NaN
00:01:00        0.060665     -0.066291      0.136705      0.000000
00:02:00        0.121326     -0.066291      0.136705      0.000000
00:03:00        0.181984     -0.066291      0.136705      0.059305
00:04:00        0.181984     -0.066291      0.205049      0.000004
00:05:00        0.181984     -0.066291      0.136710      0.059308
00:06:00        0.121330     -0.066291      0.136710      0.059308
00:07:00       -0.060643      0.000004      0.068367      0.000007
00:08:00       -0.242649      0.066295      0.136715      0.118617
00:09:00       -0.242649      0.066295      0.136715      0.059319
00:10:00       -0.181969      0.132582      0.136715      0.059319

So in this example id like to return a new dataframe with columns: Apr 04, 2014 Apr 11, 2014 Apr 24, 2015 因此,在此示例中,id喜欢返回带有列的新数据框:2014年4月4日2014年4月11日2015年4月24日

UniqueDate  Apr 04, 2014  Apr 11, 2014  Apr 24, 2015
Time                                                
00:00:00             NaN           NaN           NaN
00:01:00       -0.066291      0.136705      0.000000
00:02:00       -0.066291      0.136705      0.000000
00:03:00       -0.066291      0.136705      0.059305
00:04:00       -0.066291      0.205049      0.000004
00:05:00       -0.066291      0.136710      0.059308
00:06:00       -0.066291      0.136710      0.059308
00:07:00        0.000004      0.068367      0.000007
00:08:00        0.066295      0.136715      0.118617
00:09:00        0.066295      0.136715      0.059319
00:10:00        0.132582      0.136715      0.059319

Try: 尝试:

df.loc[:,df.columns[df.iloc[10] > 0]]

Output: 输出:

UniqueDate  Apr 04, 2014  Apr 11,  2014  Apr 24, 2014
Time                                                 
00:00:00             NaN            NaN           NaN
00:01:00       -0.066291       0.136705      0.000000
00:02:00       -0.066291       0.136705      0.000000
00:03:00       -0.066291       0.136705      0.059305
00:04:00       -0.066291       0.205049      0.000004
00:05:00       -0.066291       0.136710      0.059308
00:06:00       -0.066291       0.136710      0.059308
00:07:00        0.000004       0.068367      0.000007
00:08:00        0.066295       0.136715      0.118617
00:09:00        0.066295       0.136715      0.059319
00:10:00        0.132582       0.136715      0.059319

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

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