dimanche 1 mars 2015

Python to Excel Gets Data in bulks

I have a code that gets data from a site and should pastes to excel sheet. Till this point everything is fine except excel part. The data comes to excel in bulks I do not understand why. Normally it should be like ;



Name1
Date1 Date2 Date3 Date4
Data1 Data2 Data3 Data4

Name2
Date1 Date2 Date3 Date4
Data1 Data2 Data3 Data4

Name3
Date1 Date2 Date3 Date4 ....
Data1 Data2 Data3 Data4 ...


But I get same data - name1 for a range of A1:EO434 and then again it updates all cells for Name2 and Name3 and so on. So when the loop finishes I see only the last data copied to excel range of A1:EO434


here it is;



.... ... ... .... .. ... .. ...
mydict = data_city[:] #translation in to dictionary
for i in list(range(len(mydict))):
print data_city[i]["DistrictName"]
payload_district = {'cityId':data_city[i]["CityId"], 'lbDistricts':data_city[i]["DistrictCode"], 'criter':149,'startdate':'2003-01','cmd':'result','areaCode':data_city[i]["AreaWideCode"]}

r_district = requests.post(url, data=payload_district)

data_district = json.loads(r_district.text)
data_district = map(dict.values, data_district[u'output'][u'resultset'][u'record'][u'data'])
i = 0
for row in data_district:

Range("A"+ str(i + 1) ).value = zip(*data_district) #Not OK.
i = i+3

Aucun commentaire:

Enregistrer un commentaire