我想计算一些独特的标签值.有一些像
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) 我的熊猫数据框(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)方式?