我有一个形式的熊猫数据框

 Start Date          End Date             President       Party
0      04 March 1921    02 August 1923      Warren G Harding  Republican
1     03 August 1923     04 March 1929       Calvin Coolidge  Republican
2      05 March 1929     04 March 1933        Herbert Hoover  Republican
3      05 March 1933     12 April 1945  Franklin D Roosevelt  Democratic
4      13 April 1945   20 January 1953        Harry S Truman  Democratic
5    21 January 1953   20 January 1961   Dwight D Eisenhower  Republican
6    21 January 1961  22 November 1963        John F Kennedy  Democratic
7   23 November 1963   20 January 1969       Lydon B Johnson  Democratic
8    21 January 1969    09 August 1974         Richard Nixon  Republican
9     10 August 1974   20 January 1977           Gerald Ford  Republican
10   21 January 1977   20 January 1981          Jimmy Carter  Democratic
11   21 January 1981   20 January 1989         Ronald Reagan  Republican
12   21 January 1989   20 January 1993       George H W Bush  Republican
13   21 January 1993   20 January 2001          Bill Clinton  Democratic
14   21 January 2001   20 January 2009         George W Bush  Republican
15   21 January 2009   20 January 2017          Barack Obama  Democratic
16   21 January 2017       20 May 2017          Donald Trump  Republican


我想提取Party = Republican的索引值并将其存储在列表中。
有熊猫功能可以快速执行此操作吗?

最佳答案

df.index[df.Party == 'Republican`]


如果需要,可以在结果上调用.tolist()

关于python - Pandas -如何从数据框获取索引值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44095276/

10-12 18:47