遇到的问题---python---pandas新建空的dataframe报错dataframe type object ‘object‘ has no attribute ‘dtype‘

墨蓝 2022-10-09 12:21 81阅读 0赞

情况

处理一些数据,需要新建一个dataframe,后续再新增数据进去,使用代码如下:

  1. df=pd.DataFrame(columns=['code', 'name'])
  2. for row in results:
  3. i= i+1
  4. print(i)
  5. print("总数%s, 当前%s 编码%s" % (str(cursor.rowcount), str(i), row[0]))
  6. codeValue = row[0]
  7. nameValue = row[1]
  8. temp=[{'code':codeValue,'name':nameValue}]
  9. df=df.append(temp)

报错AttributeError: type object ‘object’ has no attribute ‘dtype’如下:

  1. Traceback (most recent call last):
  2. File "/Users/joe/workspace/stock/tianyan_py/tianyan_py/__init__.py", line 72, in <module>
  3. init()
  4. File "/Users/joe/workspace/stock/tianyan_py/tianyan_py/__init__.py", line 32, in init
  5. get_today_by_xueqiu()
  6. File "/Users/joe/workspace/stock/tianyan_py/tianyan_py/main.py", line 754, in get_today_by_xueqiu
  7. df=pd.DataFrame(colu

发表评论

表情:
评论列表 (有 0 条评论,81人围观)

还没有评论,来说两句吧...

相关阅读