AttributeError Traceback most recent call lastCell In9 line 21 18 category_sales_encoded = category_salesapplyencode_units 20 # 使用Apriori算法进行关联分析--- 21 frequent_item
出错的原因是在进行关联分析之前,对数据进行编码时出现了错误。具体来说,category_sales_encoded是一个numpy.dtype[int64]类型的对象,而该类型对象没有apply方法。
要修复这个错误,可以将category_sales_encoded转换为DataFrame类型,然后再进行关联分析。可以使用pandas.DataFrame函数将其转换为DataFrame类型,如下所示:
category_sales_encoded = pd.DataFrame(category_sales_encoded)
这样就将category_sales_encoded转换为DataFrame类型,然后可以继续进行关联分析。
原文地址: http://www.cveoy.top/t/topic/i1mZ 著作权归作者所有。请勿转载和采集!