# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import os
import pandas as pd
import datetime

# +
# Replace this directory with your respective folder
home_dir = 'D:/IU/git_repo/COVID-19/csse_covid_19_data/csse_covid_19_daily_reports/'

files = os.listdir(home_dir)

files = [f for f in files if f not in {'.gitignore', 'README.md'}]
# -

df2 = []
for f in files:
    df1 = pd.read_csv(home_dir+f)
    df1['Date'] = f
    df2.append(df1)

# +
final = pd.concat(df2).reset_index(drop=True)

final.head(2)
# -

final['Date'] = final['Date'].apply(lambda x: x.split('.')[0])

final['Date'].unique()

final['Date'] = final['Date'].apply(lambda x: datetime.datetime.strptime(x, '%m-%d-%Y'))

final['Province_State'] = final['Province_State'].fillna('')

final2 = final[['Province_State', 'Country_Region', 'Confirmed', 'Date']]

final2 = final2.groupby(['Date', 'Country_Region', 'Province_State'], as_index=False).sum()

final2 = final2.sort_values(by=['Country_Region', 'Province_State', 'Date']).reset_index(drop=True)

dates = final2.pop('Date')

confirmed = final2.groupby(['Country_Region', 'Province_State']).diff()

final2['Confirmed_daily'] = confirmed

final2['Date'] = dates

final2['Confirmed_daily'] = final2['Confirmed_daily'].fillna(0)

final2 = final2.groupby(['Country_Region', 'Province_State'], as_index=False)['Confirmed'].diff()

final2[(final2['Country_Region'] == 'US') & (final2['Province_State'] == 'Indiana')]

# # Visualization for US data ( not updated)

viz = us[['date', 'Confirmed']]

import matplotlib.pyplot as plt
# %matplotlib inline

plt.plot(viz['Confirmed'], viz['date'])

final.shape

viz.head(2)

counts = viz.groupby('date', as_index=False).sum()

counts = counts.sort_values(by='date')

counts.tail(200)

counts['Confirmed'] = counts['Confirmed'].diff().fillna(0)

from matplotlib.pyplot import figure
figure(num=None, figsize=(20, 15), facecolor='w', edgecolor='k')

final['Confirmed'].isnull().sum()

us['Confirmed'].isnull().sum()

plt.figure(figsize=(30, 30))
plt.plot(counts['date'], counts['Confirmed'])

# # Population data extraction from pdf



StarcoderdataJupyterScriptsDedupFiltered