简体   繁体   中英

How can I select data from a table with specific attribute with pandas?

I have a dataset like this: Country , Gdp , Year , Capital , Labor .

It has data from 1950 to 2014 , but I want extract data from all rows with year = 2000 . I'm using python , pandas and numpy.

IIUC you can use boolean indexing :

print df
  Country  Gdp  Year Capital  Labor 
0       a   40  2001       s      40
1       b   30  2000       u      70
2       c   70  2008       t      50

print df[df['Year'] == 2000]
  Country  Gdp  Year Capital  Labor 
1       b   30  2000       u      70

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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