Skip to content

Instantly share code, notes, and snippets.

@andrewdoss-bit
Last active August 12, 2021 21:03
Show Gist options
  • Save andrewdoss-bit/8c24414907cdac6033e55dc921a67e8f to your computer and use it in GitHub Desktop.
Save andrewdoss-bit/8c24414907cdac6033e55dc921a67e8f to your computer and use it in GitHub Desktop.
Transform
"""Provides optional transform functions for different data sources."""
import pandas as pd
def nyt_cases_counties(df):
"""Transforms NYT county-level COVID data"""
# Cast date as datetime
df['date'] = pd.to_datetime(df['date'])
# Store FIPS codes as standard 5 digit strings
df['fips'] = df['fips'].astype(str).str.extract('(.*)\.', expand=False).str.zfill(5)
# Drop Puerto Rico due to missing deaths data, cast deaths to int
df = df.loc[df['state'] != 'Puerto Rico'].copy()
df['deaths'] = df['deaths'].astype(int)
return df
# Script truncated for Medium
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment