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)
to_csv()is a pandas dataframe method.list_of_geocodersis not a dataframe, it's a list of strings (that's what I'm assumingg.json['address']is).csvmodule to write a CSV file by looping over a list. But if each element of the list is just a single string, just write them all to the file. There's nothing to separate with commas, so you don't need to use CSV-specific code.