2
我有一個DF包含英國選舉結果的結果,每個聚會一列。所以DF類似於:根據標準選擇一個熊貓數據框的列
In[107]: Results.columns
Out[107]:
Index(['Press Association ID Number', 'Constituency Name', 'Region', 'Country',
'Constituency ID', 'Constituency Type', 'Election Year', 'Electorate',
' Total number of valid votes counted ', 'Unnamed: 9',
...
'Wessex Reg', 'Whig', 'Wigan', 'Worth', 'WP', 'WRP', 'WVPTFP', 'Yorks',
'Young', 'Zeb'],
dtype='object', length=147)
例如,
Results.head(2)
Out[108]:
Press Association ID Number Constituency Name Region Country \
0 1 Aberavon Wales Wales
1 2 Aberconwy Wales Wales
Constituency ID Constituency Type Election Year Electorate \
0 W07000049 County 2015 49,821
1 W07000058 County 2015 45,525
Total number of valid votes counted Unnamed: 9 ... Wessex Reg Whig \
0 31,523 NaN ... NaN NaN
1 30,148 NaN ... NaN NaN
Wigan Worth WP WRP WVPTFP Yorks Young Zeb
0 NaN NaN NaN NaN NaN NaN NaN NaN
1 NaN NaN NaN NaN NaN NaN NaN NaN
[2 rows x 147 columns]
包含不同團體票的列是Results.ix[:, 'Unnamed: 9':]
大多數政黨投票在任何選區極少數的選票,所以我想將它們排除在外。有沒有一種方法(僅通過自己迭代每行和每列)只返回符合特定條件的列,例如至少有一個值> 1000?我非常希望能夠指定類似
Results.ix[:, 'Unnamed: 9': > 1000]