-
Notifications
You must be signed in to change notification settings - Fork 0
/
editDataSwitzerland.py
32 lines (27 loc) · 1.01 KB
/
editDataSwitzerland.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
import pandas
import os
def editDataCH():
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
# Aggregate the following file:
dfCH = pandas.read_csv('../Data/Sources/CH/COVID19_Fallzahlen_CH_total.csv')
# Load column names:
colNames = pandas.read_csv('variableTable_ALL.csv', index_col="CH")[["Measure"]].to_dict()['Measure']
dfCH = dfCH.rename(columns=colNames)
dfCH = dfCH.drop(['time', 'source'], axis=1)
# Create Region column (needed for merge with Geodata)
dfCH['Region'] = dfCH['RegionCode']
dfCH['RegionType'] = 'Canton'
dfCH['Country'] = 'CH'
dfCH = dfCH.melt(id_vars=['Country', 'Date', 'Region', 'RegionCode', 'RegionType'])
# Define function for finding rows for Liechtenstein
def CHorLI(row):
if row['RegionCode'] == 'FL':
country = "LI"
else:
country = "CH"
return(country)
dfCH['Country'] = dfCH.apply(lambda row: CHorLI(row), axis=1)
return(dfCH)
dfCH = editDataCH()