私がしたことは次のとおりです。
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])
これにはfrozensetが含まれているため、エラーが発生したため、アプリオリのデータフレームをElasticsearchに保存しようとしていました。なぜ私はそうなっているのですか?フローズンセット列をリストのリストに変換したいだけです。
データは次のようになります
。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
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
しかし、再びデータフレームで間違った結果を出しました。