小编Can*_* Lu的帖子

按多个键分组并汇总字典列表的值/平均值

什么是通过多个键进行分组的最pythonic方法,并在Python中汇总字典列表的平均值?假设我有一个字典列表如下:

input = [
{'dept': '001', 'sku': 'foo', 'transId': 'uniqueId1', 'qty': 100},
{'dept': '001', 'sku': 'bar', 'transId': 'uniqueId2', 'qty': 200},
{'dept': '001', 'sku': 'foo', 'transId': 'uniqueId3', 'qty': 300},
{'dept': '002', 'sku': 'baz', 'transId': 'uniqueId4', 'qty': 400},
{'dept': '002', 'sku': 'baz', 'transId': 'uniqueId5', 'qty': 500},
{'dept': '002', 'sku': 'qux', 'transId': 'uniqueId6', 'qty': 600},
{'dept': '003', 'sku': 'foo', 'transId': 'uniqueId7', 'qty': 700}
]
Run Code Online (Sandbox Code Playgroud)

期望的聚合输出:

output=[
{'dept': '001', 'sku': 'foo', 'qty': 400},
{'dept': '001', 'sku': 'bar', 'qty': 200},
{'dept': '002', 'sku': 'baz', 'qty': …
Run Code Online (Sandbox Code Playgroud)

python dictionary list

24
推荐指数
2
解决办法
2万
查看次数

从字符串中删除数字

我们有一大堆例如字符串:c1309,IF1306,v1309,p1209,a1309,mo1309.
在Python中,删除数字的最佳方法是什么?所有我需要的是:c,IF,v,p,a,mo从上面的例子.

python regex string

16
推荐指数
3
解决办法
2166
查看次数

标签 统计

python ×2

dictionary ×1

list ×1

regex ×1

string ×1