So I am new to python and I'm trying to do a small project which I want to do in pure pythonic way not using any additional libraries, where my data set looks like this:
LOC,DATE,ATTRIBUTE,COUNT
A,03/01/19,alpha,6483
A,03/01/19,beta,19
B,03/01/19,gamma,346158
B,02/01/19,gamma,156891
A,02/01/19,delta,1319
A,02/01/19,gamma,15272
A,02/01/19,gamma,56810
I have to transform this data set to this output:
B,02/01/19,gamma, 346158
A,02/01/19,alpha,6483
A,02/01/19,beta,19
B,02/01/19,gamma, 172163
A,02/01/19,delta,1319
B,01/01/19,gamma,56810
The data needs to be sorted by Date, Value, Measure, Loc
I thought that nested dictionaries should work, because I only have to update value of attirbute, LOC can be come the outer key
dict = {A:{}, B:{}}
Then date can be used as the key for the nested dictionary:
dict = {A:{03/01/19:{}, 02/01/19:{}}, B:{03/01/19:{}, 02/01/19:{}}
And keep going forward until I reach Count, and every time I keep updating count. But the code is getting more complex every time, my question:
- Is there any other alternative data structure that I could use?
- If with a dictionary is there a way to check nested keys and keep adding only new values for every key!
Any help would be really grateful!