-
Notifications
You must be signed in to change notification settings - Fork 0
/
UTILS.py
77 lines (69 loc) · 1.9 KB
/
UTILS.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: MijazzChan
# @Date: 2020-12-25, 9:20 PM
import json
import os
import pandas as pd
import numpy as np
selector = {'liveus': {
'date': str,
'cases': pd.Int64Dtype(),
'deaths': pd.Int64Dtype(),
'confirmed_cases': pd.Int64Dtype(),
'confirmed_deaths': pd.Int64Dtype(),
'probable_cases': pd.Int64Dtype(),
'probable_deaths': pd.Int64Dtype()
}, 'liveusstate': {
'state': str,
'fips': str,
'date': str,
'cases': pd.Int64Dtype(),
'deaths': pd.Int64Dtype(),
'confirmed_cases': pd.Int64Dtype(),
'confirmed_deaths': pd.Int64Dtype(),
'probable_cases': pd.Int64Dtype(),
'probable_deaths': pd.Int64Dtype()
}, 'liveuscounty': {
'state': str,
'fips': str,
'date': str,
'county': str,
'cases': pd.Int64Dtype(),
'deaths': pd.Int64Dtype(),
'confirmed_cases': pd.Int64Dtype(),
'confirmed_deaths': pd.Int64Dtype(),
'probable_cases': pd.Int64Dtype(),
'probable_deaths': pd.Int64Dtype()
}, 'us': {
'date': str,
'cases': pd.Int64Dtype(),
'deaths': pd.Int64Dtype()
}, 'usstate': {
'date': str,
'cases': pd.Int64Dtype(),
'deaths': pd.Int64Dtype(),
'state': str,
'fips': str
}, 'uscounty': {
'date': str,
'cases': pd.Int64Dtype(),
'deaths': pd.Int64Dtype(),
'state': str,
'fips': str,
'county': str
}
}
def toJsonFile(dataObj, filePath: str, fileName: str):
if not os.path.exists(filePath):
os.makedirs(filePath)
with open(filePath + fileName, 'w', encoding='utf-8') as f:
json.dump(dataObj, f, indent=4)
def datetime64ToStr(dateSeries: list, unit: str = 'D') -> list:
for i in range(len(dateSeries)):
dateSeries[i] = np.datetime_as_string(dateSeries[i], unit=unit)
dateSeries.sort()
return dateSeries
def dtypeDictOnRead(typeOfDataFrame: str) -> dict:
global selector
return selector[typeOfDataFrame]