-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstockGet.py
More file actions
28 lines (23 loc) · 929 Bytes
/
Copy pathstockGet.py
File metadata and controls
28 lines (23 loc) · 929 Bytes
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
import pandas as pd
import os
import tushare as ts
if __name__ == '__main__':
root_dir = 'D:\LearningProgram\stockInfo\data_0502'
save_dir = 'D:\LearningProgram\stockInfo\data_0507'
#save_dir = r'D:\LearningProgram\stockInfo\data_15_0426'
count = 0
for file_name in os.listdir(root_dir):
stock = file_name[:-4]
if file_name in os.listdir(save_dir): continue
try:
df = pd.read_csv(os.path.join(root_dir, file_name), index_col='date')
td = ts.get_hist_data(stock, start='2019-04-29')
#td = ts.get_k_data(stock, ktype='5')
df = pd.concat([td, df], sort=True).drop_duplicates(keep='first')
df = df[~df.index.duplicated(keep='first')]
df.to_csv(os.path.join(save_dir, file_name))
except:
pass
count += 1
if count % 20 == 0:
print(stock)