# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
#pip install covidcast
# -

import covidcast
from datetime import date
import pandas as pd
import pathlib



covidcast.metadata()



# ## Data to Use
# Covidcast: 
# * SafeGraph (social distancing metrics, weekly patterns) - https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals/safegraph.html - may want to look at data prior to pandemic as well since the data goes back all the way to January 1st, 2019.
# * NCHS (CDC) mortality data - https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals/nchs-mortality.html -  this data is different from the death data from USAFacts and JHU because in this data, deaths are reported by the date they occur, not the date they were reported. Also, see details regarding "Missingness" since some data was removed when death counts were 50% less of the expected number.
# * USAFacts Cases and Deaths - https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals/usa-facts.html - I plan to use this priimarily for the case count.
#
# IPUMS USA:
# Will not use this since there's no 2020 data.
#
# U.S. Bureau of Labor Statistics: https://www.bls.gov/
# Use for employment and salary data.



data = covidcast.signal("usa-facts", "confirmed_cumulative_num", date(2020, 1, 25), date(2020, 12, 31))

data.head()

data.tail()





# +
#nchs_new_death_data = covidcast.signal("nchs-mortality", "deaths_covid_incidence_num")

# +
#covidcast.signal("jhu-csse", "")
# -

usa_facts_data = covidcast.signal("usa-facts", "confirmed_cumulative_prop", date(2020, 1, 25), date(2020, 12, 31), geo_type = "state")

usa_facts_data.head()

usa_facts_data.tail()

kerstin_folder_path = pathlib.Path.cwd()

# This worked, but not like how I wanted. There's just too much extra stuff.
usa_facts_data.to_csv(kerstin_folder_path/"usafacts_cum_cases_pop_state.csv")



# Notice the many rows in the below dataframe. Ignore the index because that only matches with the state name, so the index repeats.

# +
#usafacts_cum_cases_pop_state = usa_facts_data[['geo_value','time_value','value']]
#usafacts_cum_cases_pop_state
# -





usafacts_il_county_cum_num = covidcast.signal("usa-facts", "confirmed_cumulative_prop", date(2020, 1, 25), date(2020, 12, 31), geo_type = "county", geo_values = "il")

usafacts_il_county_cum_num





usafacts_county_cum_prop = covidcast.signal("usa-facts", "confirmed_cumulative_prop", date(2020, 1, 25), date(2020, 12, 31), geo_type = "county")

# As seen by the warnings, there is no data for Feb 13-19
usafacts_county_cum_prop



usafacts_il_county_cum_7day_prop = covidcast.signal("usa-facts", "confirmed_7day_cumulative_prop", date(2020, 1, 25), date(2020, 12, 31), geo_type = "county")

usafacts_il_county_cum_7day_prop





StarcoderdataJupyterScriptsDedupFiltered