-
Notifications
You must be signed in to change notification settings - Fork 1
/
master.py
49 lines (41 loc) · 1.58 KB
/
master.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
from wrdsdata import wrdsdata
class master(wrdsdata):
"""
This is a class inherited from wrdsdata class to process master data.
Args:
startyear (int): The startyear of the desired output data.
endyear (int): The endyear of the desired output data.
month (int): The month of the desired output data; 0 means every month.
file (str): the file name of the desired output data.
"""
def __init__(self, startyear, endyear, month, file):
"""
The constructor for master class.
Args:
startyear (int): The startyear of the desired output data.
endyear (int): The endyear of the desired output data.
month (int): The month of the desired output data; 0 means every month.
file (str): the file name of the desired output data.
Returns:
no returns.
"""
wrdsdata.__init__(self, startyear, endyear, month, file)
pass
def add8CUSIP(self, y, m, newcolname, outputdir):
"""
The function to add 8-digit cusip based on 9-digit cusip in the dataset.
Args:
y (int): The year of the data.
m (int): The month of the data.
newcolname (str): The name of the newly created column of 8-digit cusip.
Returns:
no returns.
"""
filename=self._getfilename(y, m)
cusip_nan = self.d[filename][self.d[filename]['CUSIP'].isna()]
if cusip_nan.empty==False:
with open(outputdir + filename +'_CUSIP_NaN.csv', 'w') as csvFile:
cusip_nan.to_csv(csvFile, header=True, index=False)
self.d[filename] = self.d[filename].dropna(subset=['CUSIP'])
self.d[filename][newcolname] = [value[:8] for value in self.d[filename]['CUSIP']]
pass