-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_script.py
60 lines (49 loc) · 1.98 KB
/
update_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# ------
# Author: Rahul Raj (c) MIT License 2020
# Website: https://randomwalk.in
# ------
import os
from datetime import datetime
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/coder-amey/COVID-19-India_Data/master/time-series/India_regional_aggregated.csv')
# For the bubble chart
# --------------------
def format_date(date):
l = date.split('-')
l = reversed(l)
return ''.join(l)
df['Date']=df.Date.apply(format_date)
cols = ['Region', 'Date', 'Confirmed', 'Recovered/Migrated', 'Deceased']
df_ind=df.reindex(columns=cols)
df_ind.drop(index=df_ind[df_ind['Region']=='National Total'].index, inplace=True)
# backup the old data and update new datasource for the bubble chart
dtg = str(datetime.now())
dtg = dtg.split()[0]
cmd = f'move bubble\data\complete_modified_date.csv bubble\data\complete_modified_date_{dtg}.csv'
os.system(cmd)
df_ind.to_csv('bubble\data\complete_modified_date.csv', index=False)
print('Bubble chart data updated')
# For the Rank Chart, we use the same data made for Bubble Chart
# --------------------
cmd = f'move ranking\data\complete_modified_date.csv ranking\data\complete_modified_date_{dtg}.csv'
os.system(cmd)
cmd = f'copy bubble\data\complete_modified_date.csv ranking\data\complete_modified_date.csv'
os.system(cmd)
print('Rank chart data updated')
# For the line chart
# --------------------
def format_date(date):
l = date.split('-')
l = reversed(l)
return ''.join(l)
df['Date']=df.Date.apply(format_date)
cols = ['Region', 'Date', 'Confirmed', 'Recovered/Migrated', 'Deceased']
df_ind=df.reindex(columns=cols)
# df_ind.drop(index=df_ind[df_ind['Region']=='National Total'].index, inplace=True)
# backup the old data and update new datasource for the line chart
cmd = f'move line\data\complete_modified_date.csv line\data\complete_modified_date_{dtg}.csv'
os.system(cmd)
df_ind.to_csv('line\data\complete_modified_date.csv', index=False)
print('Line chart data updated')
print('Completed successfully')