Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Checking the coactivation of school and uni closures
import pandas as pd
# From
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]
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() \
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