-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.py
More file actions
51 lines (33 loc) · 1.02 KB
/
Copy pathFunctions.py
File metadata and controls
51 lines (33 loc) · 1.02 KB
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
# -*- coding: utf-8 -*-
# @Author: Xingqi Ye
# @Time: 2019-04-06-09
import pandas as pd
import config
from scipy import stats
pd.set_option('expand_frame_repr', False)
# import data
def import_data():
# import data from path
df = pd.read_csv(config.input_data_path + '/ClosePriceHSI.csv', parse_dates=['Date'])
df.sort_values(by=['Date'], inplace=True)
return df
# transfer to period data
def transfer_to_period_data(df, rule_type=' '):
'''
:param df:
:param rule_type:
5B Weekly frequency
M Month End frequency
:return:
'''
# set Date as index
df['period_date'] = df['Date']
df.set_index('Date', inplace=True)
# transfer to period data
period_df = df.resample(rule=rule_type, base=0, label='right', closed='left').last()
# reset index, put Date as the period end date
period_df.reset_index(inplace=True)
period_df['Date'] = period_df['period_date']
del period_df['period_date']
df.reset_index(inplace=True, drop=False)
return period_df