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