[docs]classUnitedStates(CountryTestBase):location="United States"source_url="https://healthdata.gov/api/views/j8mb-icvb/rows.csv"source_url_ref="https://healthdata.gov/dataset/COVID-19-Diagnostic-Laboratory-Testing-PCR-Testing/j8mb-icvb"source_label="Department of Health & Human Services"units="tests performed"rename_columns={"date":"Date"}
[docs]defpipe_metrics(self,df:pd.DataFrame)->pd.DataFrame:# daily change in positive testspos=(df[df["overall_outcome"]=="Positive"].groupby("Date",as_index=False).agg(**{"Daily change in positive total":("new_results_reported",sum)})).sort_values("Date")# daily change in total testsdf=(df.groupby("Date",as_index=False).agg(**{"Daily change in cumulative total":("new_results_reported",sum)})).sort_values("Date")# generate positive ratedf["Positive rate"]=((pos["Daily change in positive total"].rolling(7).mean())/(df["Daily change in cumulative total"].rolling(7).mean())).round(3)returndf