首页 > 解决方案 > TypeError:“numpy.ndarray”和“str”错误的实例之间不支持“>”

问题描述

#im 正在处理 covid 19 数据集的任务并使用 apriori 算法对其进行分析,但是我一直遇到问题并且我在编程方面非常糟糕 #i 首先导入了这些库

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
!pip install efficient_apriori

#加载数据

from google.colab import files
uploaded = files.upload()

#读取文件并显示

df = pd.read_csv('covid_dataset.csv')
df
#did this to turn the dataframe to a tuple
records = df.to_records(index=False)
result = list(records)

#这里有问题

from efficient_apriori import apriori
min_support = 7/len(result) 
min_confidence = 0
itemsets, rules = apriori(result, min_support=min_support, min_confidence=min_confidence)

#这里是错误

TypeError                                 Traceback (most recent call last)
<ipython-input-17-e29e44a028ef> in <module>()
      6 # For now set min_confidence = 0 to obtain all the rules
      7 min_confidence = 0
----> 8 itemsets, rules = apriori(result, min_support=min_support, min_confidence=min_confidence)

1 frames
/usr/local/lib/python3.7/dist-packages/efficient_apriori/itemsets.py in itemsets_from_transactions(transactions, min_support, max_length, verbosity, output_transaction_ids)
    312         # Retrieve the itemsets of the previous size, i.e. of size k - 1
    313         # They must be sorted to maintain the invariant when joining/pruning
--> 314         itemsets_list = sorted(item for item in large_itemsets[k - 1].keys())
    315 
    316         # Gen candidates of length k + 1 by joining, prune, and copy as set

TypeError: '>' not supported between instances of 'numpy.ndarray' and 'str'

标签: pythonpandas

解决方案


推荐阅读