
我所做的是:
a = dataframe.antecedants
print(type(a[0]))
print(a[10])
b = a.tolist()
print(type(b[10]))
print(b[10])
c = [list(x) for x in a]
print(type(c[10]))
print(c[10])我试图将我的先验数据保存到Elasticsearch,因为它包含了frozenset,所以我得到了一些错误,所以我将frozenset转换为list,在这里,当我将我的frozenset转换为list时,我得到了错误的结果。我为什么要这么做?我只想将一个冻结列转换为列表。
forzenset数据类似于:

示例:
0 (1)
1 (522)
4 (349)
5 (37)
6 (372)
7 (37)
8 (373)
9 (37)
10 (372)
11 (349)
12 (373)
13 (349)
14 (372)
15 (373)
16 (372, 349)
17 (372, 37)
18 (37, 349)
19 (372)
20 (349)
21 (37)
22 (349, 373)
23 (37, 373)我正在使用的图书馆是:
import pandas as pd
import numpy as np
from pandas.io.json import json_normalize
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules
from elasticsearch import Elasticsearch
import json然后:
dataframe = apriori(dataframe, min_support=0.1, use_colnames=True)
dataframe = association_rules(dataframe, metric="lift", min_threshold=1)
new = dataframe.copy()基本上,将frozenset list 列转换为list of lists 是我正在尝试实现的。
已更新
不过当我这么做的时候:
my_list = []
for antecedant in new.antecedants:
my_list.append(list(antecedant))
my_list这起作用了!但是:
column_values = pd.Series(my_list)
new.insert(loc=0, column='new_column', value=column_values)
new但又给出了错误的数据结果。
发布于 2018-09-02 06:21:26
new.reset_index(drop=True, inplace=True)为我工作!正如你所看到的索引是不连续后,先验和关联规则的形成,所以重置索引帮助我!
https://stackoverflow.com/questions/52134208
复制相似问题