Oct-21-2024, 11:51 AM
Hi everyone,
I am stuck with my python code. What i'm trying to do is write some informations in a json format, to a csv file.
It's dealing with GPS position over a day.
The json data returned from the API call is something like :
[
{"date": "2024-10-20T20:56:28+00:00", "latitude": 43.3013946, "longitude": 1.6932394},
{"date": "2024-10-20T20:54:24+00:00", "latitude": 43.3014407, "longitude": 1.6933062},
{"date": "2024-10-20T20:53:23+00:00", "latitude": 43.3014778, "longitude": 1.6933793}
]
and so on.
My code looks like :
I've tried with the writerows, but with no luck. Read also some python docs, but as a newbie in programming, it's a headache :)
Thanks for any help !
I am stuck with my python code. What i'm trying to do is write some informations in a json format, to a csv file.
It's dealing with GPS position over a day.
The json data returned from the API call is something like :
[
{"date": "2024-10-20T20:56:28+00:00", "latitude": 43.3013946, "longitude": 1.6932394},
{"date": "2024-10-20T20:54:24+00:00", "latitude": 43.3014407, "longitude": 1.6933062},
{"date": "2024-10-20T20:53:23+00:00", "latitude": 43.3014778, "longitude": 1.6933793}
]
and so on.
My code looks like :
import csv position = [{"date": "2024-10-20T20:56:28+00:00", "latitude": 43.3013946, "longitude": 1.6932394}, {"date": "2024-10-20T20:54:24+00:00", "latitude": 43.3014407, "longitude": 1.6933062}, {"date": "2024-10-20T20:53:23+00:00", "latitude": 43.3014778, "longitude": 1.6933793}] date = position[0]["date"] lat = position[0]["latitude"] lon = position[0]["longitude"] data = [date, lat, lon] with open('C:/positions.csv', 'a', newline='') as f: writer = csv.writer(f) writer.writerow(data)But only one row is written to the csv file, desired all rows ...
I've tried with the writerows, but with no luck. Read also some python docs, but as a newbie in programming, it's a headache :)
Thanks for any help !