获取的每天成交量可以输出数据
但是加了限定条件前十分钟成交量就变成0了
完整代码如下
- import tushare as ts
import pandas as pd
stock_code='000002'
stock_name='万科A'
start_date='2021-01-01'
end_date='2021-03-01'
stock_k=ts.get_hist_data(stock_code,start=start_date,end=end_date)
stock_table=pd.DataFrame()
for current_date in stock_k.index:
current_k_line=stock_k.loc[current_date]
df=ts.get_tick_data(stock_code,date=current_date,src='tt')
df['time']= pd.to_datetime(current_date)+pd.to_datetime('')+pd.to_datetime(df['time'])
t=pd.to_datetime(current_date).replace(hour=9,minute=40)
df_10=df[df.time<=t]
vol=df_10.volume.sum()
current_stock_info={
'名称':stock_name,
'日期':pd.to_datetime(current_date),
'开盘价':current_k_line.open,
'收盘价':current_k_line.close,
'股价涨跌幅(%)':current_k_line.p_change,
'10分钟成交量':vol
}
stock_table=stock_table.append(current_stock_info,ignore_index=True)
stock_table=stock_table.set_index('日期')