[('2016-09', 20874.73, '李四'), ('2016-10', 64296.45, '李四'), ('2016-11', 58657.1, '李四'), ('2016-12', 51253.14, '李四'), ('2017-01', 57791.88, '李四'), ('2017-01', 46007.0, '张三'), ('2017-02', 67193.55, '李四'), ('2017-02', 38352.0, '张三'), ('2017-03', 83359.53, '李四'), ('2017-03', 49661.0, '张三'), ('2017-04', 39907.0, '张三')]
I want to output the above string of data in the format
[{'data': [['2013-04', 52.9], ['2013-05-01', 50.7]], 'name': '张三'},{'data': [['2013-04', 27.7], ['2013-05-01', 25.9]], 'name': '李四'}]
With this format, is there any other way? I've been thinking about it for a long time and can't think of an effective way to do it.
In this case, the pandas module should be used to make it more sustainable:
The last line is the result you want. Basically, the index result of the third to last row is used as the basis for list derivation to produce the dictionary you want, which contains name and data, and data contains the data listed in the list
If you need more data processing, I really recommend learning the pandas module.