[英]get a value of a specific row and column in pandas dataframe
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
For example I tried : 例如我试过:
df.support.where(itemsets == ["26"])
I need to have 0.064210
as result, I would have a support of a given itemset. 结果需要为
0.064210
,我需要给定的项集。
Use tuple
to perform your comparison, not list
s. 使用
tuple
执行比较,而不是list
。
Then, use loc
and specify the column you want as below 然后,使用
loc
并指定所需的列,如下所示
df['itemsets'] = df.itemsets.transform(tuple)
df.loc[df.itemsets == ('26',), 'support']
0 0.06421
Name: support, dtype: float64
Notice you dont have to actually change your columns, eg 注意,您不必实际更改列,例如
var = df.itemsets.transform(tuple)
val_to_compare = ['26']
df.loc[var == tuple(val_to_compare), 'support']
For any ordering 对于任何订购
var = df.itemsets.transform(lambda x: tuple(sorted(x)))
val = ['26']
df.loc[var == tuple(sorted(val)), 'support']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.