解决错误TypeError: data argument can't be an iterator
来源:互联网 发布:understand mac 编辑:程序博客网 时间:2024/05/17 22:47
在学习《python数据分析与挖掘实战》第八章时,运行Apriori报错,源代码如下:
#-*- coding: utf-8 -*-from __future__ import print_functionimport pandas as pdfrom apriori import * #导入自行编写的apriori函数import time #导入时间库用来计算用时inputfile = r'...\chapter8\demo\data\apriori.txt' #输入事务集文件data = pd.read_csv(inputfile, header=None, dtype = object)start = time.clock() #计时开始print(u'\n转换原始数据至0-1矩阵...')ct = lambda x: pd.Series(1, index=x[pd.notnull(x)]) #转换0-1矩阵的过渡函数b = map(ct, data.as_matrix()) #用map方式执行data = pd.DataFrame(b).fillna(0) #实现矩阵转换,空值用0填充end = time.clock() #计时结束print(u'\n转换完毕,用时:%0.2f秒' %(end-start))del b #删除中间变量b,节省内存support = 0.06 #最小支持度confidence = 0.75 #最小置信度ms = '---' #连接符,默认'--',用来区分不同元素,如A--B。需要保证原始表格中不含有该字符start = time.clock() #计时开始print(u'\n开始搜索关联规则...')find_rule(data, support, confidence, ms)end = time.clock() #计时结束print(u'\n搜索完成,用时:%0.2f秒' %(end-start))运行后报错:TypeError: data argument can't be an iterator
在网上查后,发现Dataframe参数不能是迭代器,在本例中,b是一个map迭代器,故出错
将b进行转化,加入代码:c=list(b),并将参数c传入DataFrame中即可。代码可正常运行!
阅读全文
1 0
- 解决错误TypeError: data argument can't be an iterator
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- FileZilla 425 Can't open data connection. 的错误解决
- Parajumpers Herre happy Can't be an
- Can't convert argument
- Tomcat web.xml Can't convert argument: null错误解决办法
- ORA-00600:[32695], [hash aggregation can't be done]错误解决
- The authenticity of host 'XXXX' can't be established错误解决
- python 2.7版本解决TypeError: 'encoding' is an invalid keyword argument for this function
- TypeError: argument should be a Buffer
- TypeError:First argument must be file descriptor
- python-rrdtool创建rrd文件的TypeError: argument 0 must be string 错误
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- python提示错误TypeError: write() argument must be str, not bytes
- mui html5plus.ready事件
- 涉及到double 值比较的eps 应用
- eclipse下载及安装
- Android笔记(15)将bitmap存为文件
- STL内存管理器的分配策略
- 解决错误TypeError: data argument can't be an iterator
- 小X分集合 【map】+【模拟】
- 信源编码作业五:矢量量化LGB
- JAVA编程你必须知道的那些英文单词
- HDOJ 2544 最短路 (dijkstra算法)
- Android中的动画(三)属性动画
- java知识点归纳
- sublime-text3-自定义代码补全
- HealthInfo.java9