小编emp*_*188的帖子

Prometheus查询计算唯一标签值

我想计算一些独特的标签值.有一些像

select count (distinct a) from hello_info
Run Code Online (Sandbox Code Playgroud)

例如,如果我的度量标准'hello_info'具有标签a和b.我想要计算一个独特的数量.对于a ="1","2","3",计数将为3.

hello_info(a="1", b="ddd")
hello_info(a="2", b="eee")
hello_info(a="1", b="fff")
hello_info(a="3", b="ggg")
Run Code Online (Sandbox Code Playgroud)

grafana prometheus

10
推荐指数
3
解决办法
1万
查看次数

在python中将pandas数据框转换为字典

我的熊猫数据框(df):

Pattern      Support

Bread         4
Milk          4
Bread,Milk    4
Run Code Online (Sandbox Code Playgroud)

我的代码:

x = df.set_index('Pattern').to_dict()
print(x)
Run Code Online (Sandbox Code Playgroud)

我的代码的输出:

{'Support':{'MILK': 4,'BREAD':4, 'BREAD,MILK':4}}
Run Code Online (Sandbox Code Playgroud)

预期输出:

{'MILK': 4,'BREAD':4, 'BREAD,MILK':4}
Run Code Online (Sandbox Code Playgroud)

我不希望第二列“支持”的名称成为主键,只想获取预期输出中的元素和计数。有没有pythonic(python 3.5)方式?

python python-3.x pandas

1
推荐指数
1
解决办法
2898
查看次数

标签 统计

grafana ×1

pandas ×1

prometheus ×1

python ×1

python-3.x ×1