Python从SQL查询创建复杂的dict
在我的项目中,我运行了一个复杂的postgresql查询,创建如下输出:Python从SQL查询创建复杂的dict,python,dictionary,Python,Dictionary,在我的项目中,我运行了一个复杂的postgresql查询,创建如下输出: "25" "000006" "191215002N" 1 1.800000 "2017-01-31 00:00:00+00" 589 "25" "000009" "112036402G" 100 0.970000 "2017-01-31 00:00:00+00" 318 "25" "000009" "213008200I" 200 1.660
"25" "000006" "191215002N" 1 1.800000 "2017-01-31 00:00:00+00" 589
"25" "000009" "112036402G" 100 0.970000 "2017-01-31 00:00:00+00" 318
"25" "000009" "213008200I" 200 1.660000 "2017-01-31 00:00:00+00" 318
"25" "000009" "213008200N" 150 1.660000 "2017-01-31 00:00:00+00" 318
"25" "000009" "213008500V1" 53.5 1.930000 "2017-01-31 00:00:00+00" 318
"25" "000009" "213008500E" 61 1.930000 "2017-01-31 00:00:00+00" 318
"25" "000009" "213008500R" 56 1.930000 "2017-01-31 00:00:00+00" 318
"25" "000009" "213008200G" 50 1.660000 "2017-01-31 00:00:00+00" 318
"25" "000009" "113066592N" 20 5.583000 "2017-01-31 00:00:00+00" 318
"25" "000009" "199900502N" 321 0.725000 "2017-01-31 00:00:00+00" 318
"25" "000009" "199900602N" 360 0.680000 "2017-01-31 00:00:00+00" 318
"25" "000009" "217001100F" 1200 2.036000 "2017-01-31 00:00:00+00" 318
"25" "000009" "112031102N" 1200 0.198000 "2017-01-31 00:00:00+00" 318
"25" "000009" "112044602N" 800 0.600000 "2017-01-31 00:00:00+00" 318
"25" "000009" "112036402N" 800 0.500000 "2017-01-31 00:00:00+00" 318
"25" "000009" "113066702N" 800 0.600000 "2017-01-31 00:00:00+00" 318
"25" "000009" "113066602N" 800 0.550000 "2017-01-31 00:00:00+00" 318
"25" "000009" "112530780N3" 5000 0.178000 "2017-01-31 00:00:00+00" 318
现在,在python中使用for循环,我将创建一个复杂的dict,其子ct由上一个按此示例分组的列索引
{'<last column value unique>': {<second column>: {'total':<sum of 3 column>, 'fdata': <fourth column value>},...}, '<second unique value of last column>': {<second column>: {'total':<sum of 3 column>, 'fdata': <fourth column value>}}, ...}
但是我不明白如何用python为像这样的dict创建n my循环
有人能帮我吗
非常感谢
A我认为最好是根据输入而不是列数包含预期的输出。您能包括预期的输出吗?好的,添加带有数据的示例,对不起,谢谢
{'589': {'191215002N': {'total':1.80, 'fdata': '2017-01-31'}}, '318': {'112036402G': {'total':970 'fdata': '2017-01-31'},'213008200I': {'total':332 , 'fdata': '2017-01-31'},'213008200N': {'total':249 ', fdata': '2017-01-31'}, ...}, ...}