import tushare as ts
import pandas as pd
import numpy as np
#import mpl_finance as mpf 已过时
import mplfinance as mpf
def str_to_date(str):
if len(str)==8:
return str[0:4]+'-'+str[4:6]+'-'+str[6:8]
else:
return str
pro = ts.pro_api()
df = pro.daily(ts_code='000625.SZ', start_date='20180701', end_date='20200708')
#print(df)
period_type = 'D'
print(df)
#df = df[['ts_code','trade_date', 'open', 'close', 'high', 'low']]
df['trade_date']=df['trade_date'].apply(str_to_date)
df['trade_date'] = pd.to_datetime(df['trade_date'])
df=df.rename(columns={'vol': 'volume'})
df.to_excel('000625.xlsx')
print(df)
结果:
ts_code trade_date open high low close pre_close change
0 000625.SZ 20200708 12.88 13.18 12.7