itemsets = [["26"], ["51", "28", "27"], ["50"], ["8"], ["81", "15"], ["10"], ["81"]]
support = [0.06421, 0.00123, 0.04112, 0.0112, 0.12097, 0.08123, 0.0021334]
df = pd.DataFrame()
df["itemsets"]= itemsets
df["support"] = support
print(df)
itemsets support
0 [26] 0.064210
1 [51, 28, 27] 0.001230
2 [50] 0.041120
3 [8] 0.011200
4 [81, 15] 0.120970
5 [10] 0.081230
6 [81] 0.002133
例如,我尝试过:
df.support.where(itemsets == ["26"])
我需要得到0.064210
,我将支持给定的项目集。
答案 0 :(得分:0)
使用tuple
而不是list
来进行比较。
然后,使用loc
并在下方指定所需的列
df['itemsets'] = df.itemsets.transform(tuple)
df.loc[df.itemsets == ('26',), 'support']
0 0.06421
Name: support, dtype: float64
请注意,您不必实际更改列,例如
var = df.itemsets.transform(tuple)
val_to_compare = ['26']
df.loc[var == tuple(val_to_compare), 'support']
对于任何订购
var = df.itemsets.transform(lambda x: tuple(sorted(x)))
val = ['26']
df.loc[var == tuple(sorted(val)), 'support']