weixin_46617641 2022-05-18 16:29 采纳率: 92.3%
浏览 176
已结题

tushare爬虫提示'NoneType' object has no attribute 'head'

问题相关代码,请勿粘贴截图
ts.get_tick_data('000300',date='2021-10-20',src='tt').head()#历史分笔数据
# vpin计算,其中start,end为时间,code为股票代码,注意tushare的高频数据最早到20186月
def vpin(start, end, code):
    tradeday = get_trade_days(start_date=start, end_date=end)
    firstday = ts.get_tick_data(code, date=str(tradeday[0]), src='tt')
    firstdayvol = firstday['volume'].sum()
    bulkvol = firstdayvol / 50
    result = pd.DataFrame(columns=('date', 'vpin', 'high', 'low', 'open', 'close'))
    datelist = []
    allchange = []
    for i in tradeday:

        day = ts.get_tick_data(code, date=str(i), src='tt')
        if day is not None:
            day['volcum'] = day['volume'].cumsum()
            day['number'] = day['volcum'] // bulkvol
            n = int(max(day['number']))

            for j in range(0, n):
                bulk = day[day['number'] == j]
                if len(bulk) > 0:
                    change = (bulk.iloc[-1]['price'] / bulk.iloc[0]['price']) - 1
                    allchange.append(change)

    std = np.std(np.array(allchange))

    for i in tradeday:
        day = ts.get_tick_data(code, date=str(i), src='tt')
        if day is not None:
            chglist = []
            vpinlist = []
            day['volcum'] = day['volume'].cumsum()
            day['number'] = day['volcum'] // bulkvol
            n = int(max(day['number']))
            high = max(day['price'])
            low = min(day['price'])
            Open = day['price'].iloc[0]
            Close = day['price'].iloc[-1]

            for j in range(0, n):
                bulk = day[day['number'] == j]
                if len(bulk) > 0:
                    change = (bulk.iloc[-1]['price'] / bulk.iloc[0]['price']) - 1
                    chglist.append(change)
            for change in chglist:
                z = (change) / std
                p = (1.0 + erf(z / sqrt(2.0))) / 2.0
                vpinlist.append(abs(((1 - p) - p)))
        vpin = np.mean(np.array(vpinlist))
        result = result.append(
            pd.DataFrame({'date': [i], 'vpin': [vpin], 'high': [high], 'open': [Open], 'low': [low], 'close': [Close]}),
            ignore_index=True)
    return result
运行结果及报错内容

img

  • 写回答

1条回答 默认 最新

  • 二九筒 2022-05-18 16:42
    关注

    你 print一下这个ts.get_tick_data('000300',date='2021-10-20',src='tt') 看是不是None

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 8月11日
  • 已采纳回答 8月3日
  • 创建了问题 5月18日

悬赏问题

  • ¥15 CMAKE+VS2019+QT5.15.2组合进行二次编译
  • ¥15 nginx 配置静态html访问 ,后台登录时页面始终被重定向到登录页,无法访问到后台的静态html页
  • ¥20 自动登录的j2ee程序编译
  • ¥15 fluent模拟静态气体扩散
  • ¥15 java根据模板,生成word文档,需要带目录
  • ¥15 广告联盟的兜底广告是什么意思
  • ¥15 如何证明高斯噪声的包络公式
  • ¥150 寻找王者荣耀开发作者,合作或者解答
  • ¥15 关于cpci总线的几个问题,别用人工智能回答
  • ¥15 乳腺癌数据集 相关矩阵 特征选择