Skip to content

Instantly share code, notes, and snippets.

@g-leech
Created May 8, 2020 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g-leech/6527d3f68375224831bb7aac63aaf15f to your computer and use it in GitHub Desktop.
Save g-leech/6527d3f68375224831bb7aac63aaf15f to your computer and use it in GitHub Desktop.
Checking the coactivation of school and uni closures
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