I would like to receive a data series in excel such;
Name 1
Year 1 Year 2 Year 3 Year 4 Year 5 Year 6 Year 7 Year 8 Year 9 ...
Data 1 Data 2 Data 3 Data 4 Data 5 Data 6 Data 7 Data 8 Data 9 ...
Name 2
Year 1 Year 2 Year 3 Year 4 Year 5 Year 6 Year 7 Year 8 Year 9 ...
Data 1 Data 2 Data 3 Data 4 Data 5 Data 6 Data 7 Data 8 Data 9 ...
Name 3
Year 1 Year 2 Year 3 Year 4 Year 5 Year 6 Year 7 Year 8 Year 9 ...
Data 1 Data 2 Data 3 Data 4 Data 5 Data 6 Data 7 Data 8 Data 9 ...
.......................
Problem is that, the data is not transposed and when the second data comes it overrides on it and goes like that. So at the end i see the last data. What i would like to do is that to transpose the row to A1 lets say, then when the new data comes from the loop it writes to A3. Here what i see with the existing code;
Year 1 Date 1
Year 2 Date 2
Year 3 Date 3
Year 4 Date 4
Year 5 Date 5
Year 6 Date 6
Year 7 Date 7
Year 8 Date 8
Year 9 Date 9
Year 10 Date 10 .....
Here is the code;
from xlwings import Workbook, Sheet, Range, Chart
import requests
import json
payload_city = {'cityId':3969, 'cmd':'districts'}
url = "http://ift.tt/1MUARz5"
r_city = requests.post(url, data=payload_city)
data_city = json.loads(r_city.text) #json to python data structure conversion
#wb = Workbook()
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 = row
i=i+1
I also tried the last part like that;
i = 0
for row in data_district:
Range("A" + str(i + 1) ).value = zip(*data_district)
i=i+1
did not work, or;
for row in data_district:
Range("A1).value = zip(*data_district)
did not work either and I could not find how to move to other cell.
Thank you in advance
Aucun commentaire:
Enregistrer un commentaire