I have a csv file file1.csv whose sample structure is like this(the state below are abbreviations of US states):
companyid,state,amount
A,AL,609
A,AL,589
A,AL,915
A,AL,344
A,AL,813
A,AL,825
A,AL,825
A,AL,219
A,AL,778
A,AL,145
A,AL,983
A,AL,621
A,AR,339
A,AR,269
Notice that the data above is for multiple companyid's (records of company A followed by records of company B and so on) and within each company there are records for multiple states(you can see records for states AL followed by AR for company A above). In the data file for each companyid and for each state within that companyid there are 12 records.
Also I have a python dictionary dict1 whose structure is like this:
{'Mississippi': ['102738', '104143', '104046', '102727', '103769', '102865', '105348', '104399', '103016', '105377', '105184', '105829'], 'Oklahoma': ['166332', '167224', '168511', '175317', '171668', '176352', '178444', '179126', '179582', '182935', '186687', '184799'], 'Delaware': ['59254', '59357', '59248', '58559', '59715', '60559', '60829', '62160', '61094', '62375', '63646', '63908'], 'Minnesota': ['294611', '292213', '298997', '297042', '302542', '303040', '311457', '312043', '309764', '312677', '320114', '322264'],.....}
Here the key is the state name and values for that key are 12 numbers. Apart from that I have function func1(list1,list2) which takes two list parameters list1 and list2.
Now what I want do is that for each companyid from the csv file and then for each state within that companyid, form the two lists - list1 will have 12 records from the csv file (Notice that for each companyid and for each state within that companyid there are exactly 12 records in csv file) and list2 which will have 12 records from the dictionary dict1 for that state(the state needs to mapped). These two lists needs to passed to the function func1() each time so that the func1() is called each time for each company and for each distinct state within that company once.
One thing to note that the state in csv file are in abbreviated format while in dictionary dict1 they are in full format. For this I have created a separate dictionary which has following structure:
states = {
'AK': 'Alaska',
'AL': 'Alabama',
'AR': 'Arkansas',
'AS': 'American Samoa',
'AZ': 'Arizona',
'CA': 'California',
'CO': 'Colorado',
'CT': 'Connecticut',
'DC': 'District of Columbia',
'DE': 'Delaware',
'FL': 'Florida',
'GA': 'Georgia',
'GU': 'Guam',
'HI': 'Hawaii',
'IA': 'Iowa',
'ID': 'Idaho',
'IL': 'Illinois',
.
.
.
I am having difficulty in understanding how to do it? Can anyone help me in this?
NOTE: The desired structure that I want is:
for each companyid and for each state in that companyid in csv file:
list1 = 12 records from the csv file
list2 = 12 records from the dictionary after mapping the abbreviated state through the state dictionary that I have
call func1(list1,list2)
companyidin csv file and for eachstatewithin thatcompanyidI want to form two lists - list1 will have 12 records from the csv file (Notice that for each companyid and for each state within that companyid there are exactly 12 records in csv file) and list2 which will have 12 records from the dictionary dict1 for that state(the state needs to mapped) and then pass there two lists to thefunc1(list1,list2)