add pandas df filtering exercise
All threads resolved!
All threads resolved!
for context: the dataframe mentioned in the exercise is built from this CSV, i.e.
covid_cases = pd.read_csv('https://git.embl.de/grp-bio-it-workshops/intermediate-python/-/raw/master/data/CovidCaseData_20200624.csv')
one possible solution would be:
covid_cases[covid_cases['year'] == 2019][covid_cases['cases'] > 0]
Happy for review from anyone @ralves @meechan @ext.bauer
Merge request reports
Activity
Filter activity
mentioned in merge request !12 (merged)
- Resolved by Toby Hodges
Nice exercise. Like it. I could not test the compilation.
Remark on solution:
Proposed solution leads to UserWarning, as index array of second "filter" is too large for result of first filter.
In [9]: covid_cases[covid_cases['year'] == 2019][covid_cases['cases'] > 0] <ipython-input-9-de53dbbe1f91>:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index. covid_cases[covid_cases['year'] == 2019][covid_cases['cases'] > 0] Out[9]: dateRep day month year ... geoId countryterritoryCode popData2019 continentExp 5181 31/12/2019 31 12 2019 ... CN CHN 1.433784e+09 Asia [1 rows x 11 columns]
Proposal: Combine index arrays with booleans
c = covid_cases c[(c['year']==2019) & (c['cases']>0)]
Explanation:
In [1]: import pandas as pd In [2]: covid_cases = pd.read_csv('https://git.embl.de/grp-bio-it-workshops/intermediate-python/-/raw ...: /master/data/CovidCaseData_20200624.csv') In [3]: c0 = covid_cases In [4]: c1 = c0[c0['year']==2019] In [5]: c2 = c1[c1['cases']>1] In [6]: c1[c0['cases']>1] <ipython-input-6-81a87b0cc528>:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index. c1[c0['cases']>1] Out[6]: dateRep day month year ... geoId countryterritoryCode popData2019 continentExp 5181 31/12/2019 31 12 2019 ... CN CHN 1.433784e+09 Asia [1 rows x 11 columns]
Edited by Julian Bauer
added 25 commits
-
37f4c945...ad8ef3a1 - 24 commits from branch
master
- 8dae2aac - merge master
-
37f4c945...ad8ef3a1 - 24 commits from branch
- Resolved by Toby Hodges
added 50 commits
-
8dae2aac...4db1717c - 49 commits from branch
master
- 30fd6329 - merge master
-
8dae2aac...4db1717c - 49 commits from branch
mentioned in commit 666a5414
Please register or sign in to reply