python pandas 环境 迭代生成dataframe 出错,求大神指导

zgjsswjw 2018-07-25 06:05:02
import numpy as np
import pandas as pd
from pandas import Series,DataFrame
import tushare as ts


hy=ts.get_industry_classified()
hy=hy[hy['c_name']=='环保行业']
cfgp=np.array(hy.code)
cfgp=cfgp.tolist()
cfgp=list(cfgp)


heji=pd.DataFrame()
for xx in cfgp:
gp=ts.get_hist_data(xx)
gp['code']=xx
heji=heji.append(gp)


print(heji.shape)

-------------------------------------

Traceback (most recent call last):
File "d:\jiangwei\Documents\python_code\test2.py", line 22, in <module>
gp['code']=xx
TypeError: 'NoneType' object does not support item assignment

一直报错,弄了好久都解决不了,求大神指导,带我出坑。
...全文
180 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgjsswjw 2018-07-26
  • 打赏
  • 举报
回复
发现问题原因了,原来是tushare的数据接口有问题!ts.get_hist_data('300332')返回值为 none ,而cfgp里刚好有'300332'这个元素!
欢乐的小猪 2018-07-26
  • 打赏
  • 举报
回复
元素多的时候包含了非预知规则的数据。你可以try下
zgjsswjw 2018-07-26
  • 打赏
  • 举报
回复
引用 1 楼 ghostgoodbye的回复:
这个报错说明ts.get_hist_data(xx)的返回值为None,你要看看原因了,是参数xx传的不对,还是什么问题
如果把gp['code']=xx这段话注释掉就运行正常,或者减少cfgp这个list中的元素数量的话也正常,元素一多就报错!
ghostgoodbye 2018-07-26
  • 打赏
  • 举报
回复
这个报错说明ts.get_hist_data(xx)的返回值为None,你要看看原因了,是参数xx传的不对,还是什么问题

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧