Frozenset doesn't display its contents in Spyder Variable Explorer

安稳与你 提交于 2020-01-16 15:45:55

问题


After applying apriori algorithm to Market Basket Optimization data set when I open the rule in Spyder, instead of showing frozenset({'light cream', 'chicken'}) shows frozenset object of builtins module

My code:

import pandas as pd

# Read dataset
dataset = pd.read_csv('Market_Basket_Optimisation.csv', header = None)
transactions = []
for i in range(0, 7501):
transactions.append([str(dataset.values[i,j]) for j in range(0, 20)])

# Train model
from apyori import apriori
rules = apriori(transactions, min_support = 0.003, min_confidence = 0.2, min_lift = 3, min_length = 2)

# To get the output 
results = list(rules)

Dataset

Images for reference:

First case

Second case


回答1:


(Spyder maintainer here) Short answer: The reason for this problem is very simple: we don't support frozenset's in our Variable Explorer. That's why they are not displayed unless you turn off the option called Exclude unsupported data types, and after that they are shown as generic objects.

Long answer: We can't simply use the repr of an object to display that in the Variable Explorer. That's because if your object is quite complex (i.e. it has too many elements or it's composed of objects with long repr's), the Spyder console hangs trying to compute its repr. We learned that the hard way after many years of supporting complex scientific workflows.

So for each type object we need to decide how it's going to be displayed in the Variable Explorer. For example, we show Column names for Dataframes and the ten first elements of lists and dicts. We already have a small library to do that, but we need to expand it every time people wants to see new type objects.

Note: We plan to do that process extendible by plugins in Spyder 4 (to be released in 2019).




回答2:


You need to perform a print(results), because the Variable Explorer in Spyder does not support frozenset data types.




回答3:


To print each rule with a bit of separation in between, try"

for i in results:
    print(i)
    print('**********')


来源:https://stackoverflow.com/questions/50211040/frozenset-doesnt-display-its-contents-in-spyder-variable-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!