paulmz

us_confirmed

May 14th, 2020
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. BASE_URL = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/'
  4. CONFIRMED = 'time_series_covid19_confirmed_global.csv'
  5. DEATH = 'time_series_covid19_deaths_global.csv'
  6. RECOVERED = 'time_series_covid19_recovered_global.csv'
  7. CONFIRMED_US = 'time_series_covid19_confirmed_US.csv'
  8. DEATH_US = 'time_series_covid19_deaths_US.csv'
  9. REFERENCE = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/UID_ISO_FIPS_LookUp_Table.csv'
  10. SOURCE_DIR = 'source_data/'
  11. DEST_DIR = 'dest_data/'
  12. US_CONFIRMED = 'us_confirmed.csv'
  13.  
  14.  
  15. def process():
  16.  
  17.     df = pd.read_csv(BASE_URL + CONFIRMED_US, dtype={'Lat': str, 'Long_': str}) # dd.SOURCE_DIR +, dd.BASE_URL +
  18.     df.set_index(['UID','iso2','iso3', 'code3', 'FIPS', 'Admin2','Lat','Combined_Key',
  19.                   'Province_State', 'Country_Region', 'Long_'], inplace=True)
  20.     df = df.stack()
  21.     df = df.reset_index().set_index('UID')
  22.     df.rename(columns={"Long_": "Long", "Country_Region": "Country/Region", "Province_State": "Province/State",
  23.                        "level_11": "Date", 0: "Case"}, errors="raise", inplace=True)
  24.     df = df[df.columns[[0,1,2,3,4,5,6,10,11,9,8,7]]]
  25.     df["FIPS"].fillna("", inplace=True)
  26.     df['Date'] = pd.to_datetime(df['Date'])
  27.  
  28.     df.to_csv(DEST_DIR + US_CONFIRMED)
  29.  
  30.  
  31. process()
Add Comment
Please, Sign In to add comment