[英]How do you calculate the cdf of a linear transformation of the normal distribution in python?
[英]How do you calculate the distribution of frequencies in a list in Python?
我可能只是用错误的词来搜索这个问题,因为它并没有让我觉得那么复杂,但似乎无法在 StackOverflow 上找到答案
我有一个字符串列表;
'Pelican Point',
'Bridgetown',
'Dunsborough',
'Gelorup',
'Ambergate',
'Gelorup',
'Yallingup Siding',
'East Bunbury',
...
'West Busselton',
'Vasse',
'Yallingup',
'West Busselton',
'Bunbury',
'Collie',
'Vasse',
'Dunsborough',
'Dunsborough',
'Australind',
'Busselton',
'Busselton',
'Abbey',
'Dalyellup',
'Quindalup'
我想计算一下;
这可能吗?
您可以使用collections.Counter
构建频率 map,其中键是唯一的字符串,值是频率。
之后,您的查询变得简单明了。
这是你想要的吗? 您可以根据需要更改“if-elif”条件内的代码。
lst = [ 'Pelican Point', 'Bridgetown', 'Dunsborough', 'Gelorup','Ambergate', 'Gelorup', 'Yallingup Siding', 'East Bunbury', 'West Busselton', 'Vasse', 'Yallingup', 'West Busselton', 'Bunbury', 'Collie', 'Vasse', 'Dunsborough', 'Dunsborough', 'Australind', 'Busselton', 'Busselton', 'Abbey', 'Dalyellup', 'Quindalup']
S = set(lst)
for e in S:
c=lst.count(e)
if(c==1):
print("count for ",e, " is ",c)
elif(c>=2 or c<=5):
print("count for ",e, " is ",c)
else:
print("count for ",e," is ",c)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.