Created
May 8, 2020 10:26
-
-
Save g-leech/6527d3f68375224831bb7aac63aaf15f to your computer and use it in GitHub Desktop.
Checking the coactivation of school and uni closures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# From https://www.notion.so/977d5e5be0434bf996704ec361ad621d?v=fe54f89ca9e04ac799af42b39e1efc4b | |
path = "COVID 19 Containment measures data.csv" | |
df = pd.read_csv(path) | |
withoutUS = df[~df["Country"].str.contains("US:")] | |
withoutUS = withoutUS[~withoutUS["Country"].str.contains("United States")] | |
numCountries = withoutUS.Country.unique().shape[0] | |
#df[df.Country.isnull()].shape[0] | |
withoutUSorNulls = withoutUS[~withoutUS.Keywords.isnull()] | |
countries = withoutUSorNulls.groupby("Country") | |
sameRow = lambda df : df.Keywords.str.contains("school closure") \ | |
& df.Keywords.str.contains("university closure") | |
simultaneousCountries = countries.apply(sameRow) | |
numCoactivations = simultaneousCountries.sum() | |
withSchoolRows = withoutUSorNulls[withoutUSorNulls.Keywords.str.contains("school closure")] | |
numCountriesWithSchoolClosureInOurData = withSchoolRows.Country.unique() \ | |
.shape[0] | |
print( numCoactivations / numCountries, "of all countries in our sample" ) | |
print( numCoactivations / numCountriesWithSchoolClosureInOurData, "of countries with school closure noted in our sample" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment