Last active
          August 12, 2021 21:03 
        
      - 
      
 - 
        
Save andrewdoss-bit/8c24414907cdac6033e55dc921a67e8f to your computer and use it in GitHub Desktop.  
    Transform
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | """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