<jupyter_start><jupyter_text>COVID-19 Cases by County<jupyter_code># these are the Python packages being used for data collection and analysis
import datetime
import requests
import pandas as pd

# this is the URL that supplies the COVID data by county
URL = "https://opendata.arcgis.com/datasets/0573e90adab5434f97b082590c503bc1_0.geojson"

r = requests.get(URL)

# this will shut down the data transformation if there was an HTTP issue
r.raise_for_status()

# this collects the relevant part of the response object and converts it
# into something we can turn into a dataframe (table)
json_list = []
for item in r.json()['features']:
  json_list.append(item['properties'])

# this formats the dataframe to have county columns and date rows
df = pd.DataFrame(json_list)
df = df.set_index('DATE')
df.index = df.index.map(pd.to_datetime)
df = df.drop('OBJECTID', axis=1)

# this checks whether today's data is included in the dataframe
if df.index[-1].date() == datetime.datetime.now(tz=datetime.timezone(datetime.timedelta(hours=-4))).date():
  print("Fresh data present, good to go")
else:
  print("Today's data is NOT present")
# no need to re-run this cell!
# this is the list of counties in the dataframe
# you'll have to reproduce how they're rendered here to visualize them
df.columns
# to cut off the earliest days from the chart and only look at the most recent n,
# set this variable to your desired value of n
# to see all the data from the beginning, set it to 0
truncate = 0

# these are the counties used for the visualization
# if you want to add more, make sure they're comma-separated and enclosed in quotes
counties = ['Baltimore', 'Baltimore_City', 'Anne_Arundel']

df[counties].iloc[-truncate:].plot.line(title="Cumulative Cases by County", figsize=(15,9), grid=True);
# to look at new cases over the past n days,
# set this variable to your desired value of n
past_days = 7

# to cut off the earliest days from the chart and only look at the most recent n,
# set this variable to your desired value of n
# to see all the data from the beginning, set it to 0
truncate2 = 0

# these are the counties used for the visualization
# if you want to add more, make sure they're comma-separated and enclosed in quotes
counties2 = ['Baltimore', 'Baltimore_City', 'Anne_Arundel']

# this generates a new dataframe based on cumulative case count dataframe
# the value for a given (county, date) is equal to the number of new cases
# in that county in the past n days
df2 = df.diff(periods=past_days) / past_days

df2[counties2].iloc[-truncate2:].plot.line(title=f"Average number of new cases per day in the past {past_days} days",
                                          figsize=(15,9), grid=True);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08509861212563916, 'fraction_numerical': 0.01643535427319211, 'mean_word_length': 4.434523809523809, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '118462', 'license': 'MIT', 'n_tokens_mistral': 864, 'n_tokens_neox': 806, 'n_words': 362, 'path': 'COVIDbyCounty.ipynb', 'repo_name': 'srfinley/MD-covid-viewer', 'size': '2738'}