Reputation: 1
I'm trying to download filtered geojson data i've downloaded from simplemaps.com into a CSV file from google colab. However I keep getting an attribute error:'list' object has no attribute 'to_csv'. Code below. Any help would be greatly appreciated.
list_of_geocoders=[]
for i in tqdm(all_cities):
geo=geocoder.osm(i,maxRows=2) #maxRow =2 means it will pick first 2 results for each city, in case the first result is not of type = 'administrative'
for g in geo:
if g.json['type'] == 'administrative' :
if g.json['address'] not in list_of_geocoders: #avoid repetition
list_of_geocoders.append(g.json['address'])
from google.colab import drive
drive.mount('/content/drive')
path = '/content/drive/My Drive/outpur.csv'
with open(path, 'w', encoding = 'utf-8-sig') as f:
list_of_geocoders.to_csv(f)
Upvotes: 0
Views: 496
Reputation: 782693
to_csv()
is for writing a pandas dataframe to a CSV fgile.
If you have a list of strings, just write each string to the file directly.
with open(path, 'w', encoding = 'utf-8-sig') as f:
for address in list_of_geocoders:
f.write(f'{address}\n')
Upvotes: 1