text_plain_output_1.png
from plotly.subplots import make_subplots

from sklearn.preprocessing import LabelEncoder

import pandas as pd

import plotly.express as px

train_df = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/train.csv')
test_df = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/test.csv')
submission = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/submission.csv')

train_df.isna().sum()

test_df.isna().sum()

all_data = pd.concat([train_df, test_df], axis=0, sort=False)
all_data['Province_State'].fillna('None', inplace=True)
all_data['ConfirmedCases'].fillna(0, inplace=True)
all_data['Fatalities'].fillna(0, inplace=True)
all_data['Id'].fillna(-1, inplace=True)
all_data['ForecastId'].fillna(-1, inplace=True)

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
all_data['Date'] = pd.to_datetime(all_data['Date'])
all_data['Day_num'] = le.fit_transform(all_data.Date)
all_data['Day'] = all_data['Date'].dt.day
all_data['Month'] = all_data['Date'].dt.month
all_data['Year'] = all_data['Date'].dt.year

train = all_data[all_data['ForecastId'] == -1.0]
test = all_data[all_data['ForecastId'] != -1.0]

temp = train.groupby('Date')['ConfirmedCases', 'Fatalities'].sum().reset_index()
temp = temp.melt(id_vars='Date', value_vars=['ConfirmedCases', 'Fatalities'], var_name='case', value_name='count')
fig = px.line(temp, x='Date', y='count', color='case', title='Total cases over the Date ', color_discrete_sequence=['cyan', 'red'])

country_max = train.groupby(['Date', 'Country_Region'])['ConfirmedCases', 'Fatalities'].max().reset_index().sort_values(by='ConfirmedCases', ascending=False).groupby('Country_Region').max().reset_index().sort_values(by='ConfirmedCases', ascending=False)
country_max[:20].style.background_gradient(cmap='viridis_r')

Top_country = train.groupby('Country_Region')['ConfirmedCases', 'Fatalities'].max().reset_index().sort_values(by='ConfirmedCases', ascending=False).head(15)
fig_c = px.bar(Top_country.sort_values('ConfirmedCases'), x='ConfirmedCases', y='Country_Region', text='ConfirmedCases', orientation='h', color_discrete_sequence=['cyan'])
fig_d = px.bar(Top_country.sort_values('Fatalities'), x='Fatalities', y='Country_Region', text='Fatalities', orientation='h', color_discrete_sequence=['red'])
fig = make_subplots(rows=1, cols=2, shared_xaxes=False, horizontal_spacing=0.14, vertical_spacing=0.08, subplot_titles=('Confirmedcases', 'Fatalities'))
fig.add_trace(fig_c['data'][0], row=1, col=1)
fig.add_trace(fig_d['data'][0], row=1, col=2)