i have this function
def audience(lat,lon,ids):
buff = buff_here(lat,lon)[-1]
count_visitas = []
for visitas in glob.glob(path): ......
df = pd.DataFrame(count_visitas, columns =['Visitas'])
df.to_csv(f'output/visitas_simi_{ids}.csv', index = False)
return count_visitas
I can't post the complete code here due to work issues, but it's works perfectly fine if i pass this parameters
audience(-33.51133739,-70.7558227,'CL0008')
Now, i have this csv and want to iterate over the rows of lat, lon and id as a parameter of the function. Any help, please? :c
CodePudding user response:
You would need to bring the csv in with csv.DictReader
and then you can call the desired columns:
csv_file = csv.DictReader(open(file, 'rU'))
for row in csv_file:
count_visitas = audience(row['lat'],row['lon'],row['ids'])
CodePudding user response:
This code should work:
import csv
with open("names.csv", "r") as csv_file:
csv_reader = csv.DictReader(csv_file)
for line in csv_reader:
lat = line["first_name"]
lon = line["last_name"]
ids = line["email"]
audience(lat, lon, ids)