Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.