Write python object to multi-column csv file
I am using Google Geocode API to append more detailed geographical
information to a list of addresses. That is to say, in a spreadsheet, I
want to append columns of sub-district (an administrative unit in India),
city and village specifically to each observation (address).
I've already imported the address into python in an ugly way and used
Google API together with some codes to convert this page
(http://maps.googleapis.com/maps/api/geocode/json?address=RAVI+NAGAR,+NAIDU+THOTA,+VISAKHAPATNAM+&sensor=true
) into the following printout:
Ravi Nagar [u'neighborhood', u'political']
Naidu Thota [u'sublocality', u'political']
Vizag [u'locality', u'political']
Vishakhapatnam [u'administrative_area_level_2', u'political']
Andhra Pradesh [u'administrative_area_level_1', u'political']
India [u'country', u'political']
530029 [u'postal_code']
as search result for address string:
"RAVI+NAGAR,+NAIDU+THOTA,+VISAKHAPATNAM+",Visakhapatnam,ANDHRA+PRADESH.
My question is, how to get these back to the previous csv file? I mean, I
don't want to miss the previous rows of the csv file and I want to append
new columns to the table. (Given the above result, I would like to have
columns for "postal_code", "administrative_area_level_1",
"administrative_area_level_2", "locality", "sublocality" and
"neighborhood" respectively. What I can think of is to construction a
function with identifier but I don't know that method according to my
shallow knowledge of Python.
One more minor point to ask: does it matter for u to show up in the
printouts? How to remove it? I mean remove the u in the "result"
dictionary (for this, you can click the link I've provided)?
Thank you for your help!
Linfeng
No comments:
Post a Comment