Help organizing data pulled from data Mining a CSV
Overview
The program will open a sample data file that contains information about villages in Afghanistan and mine it for valuable information. It will list the district and its size and then all villages located within that district. The final data set may have the columns in an arbitrary order and will not match the sample data set.
Specification
The program requires you to read the contents of the data file, two of which are provided (SampleData1.csv and SampleData2.csv). Once the data is read you then need to determine a way to access the information correctly by keeping track of the column title and its index. Once you can access the appropriate columns (the district name, the village name and the size in hectares) you need to then create a data structure that associates each district with all of the villages within its boundary as well as each district with its area in hectares. Be sure you are checking for malformed lines in your data or your program may fail to run to completion.
These are my requirements. So far I have been able to locate and pull the needed datd from the file but my problem come when dealing with storing it before printing and storing it in the data.txt. I don't know how to deal with multiple villages from the same district. My code is below any hints will be appreciated.
def storeInfo(lines,districtIndex, villageIndex, areaIndex):
districtList = []
for villageLine in lines:
villageLine = villageLine.split(',')
district = villageLine[districtIndex]
if district:
districtList.append(district)
print districtList
Posted Dec 2, 2012, 7:51 PM UTC