Saving zip list to csv in Python -


how can write below zip list csv file in python?

[{'date': '2015/01/01 00:00', 'v': 96.5},  {'date': '2015/01/01 00:01', 'v': 97.0},  {'date': '2015/01/01 00:02', 'v': 93.75},  {'date': '2015/01/01 00:03', 'v': 96.0},  {'date': '2015/01/01 00:04', 'v': 94.5} 

i have error:

_csv.error: sequence expected 

my code here:

import csv res = zip_list csvfile = "/home/stm/pycharmprojects/isbak_trafik/example.csv"  open(csvfile, "w") output:     writer = csv.writer(output, lineterminator='\n')     writer.writerows(res) 

writer.writerows expects sequence of values writing single row csv file.

using original code:

import csv res =[{'date': '2015/01/01 00:00', 'v': 96.5}, {'date': '2015/01/01 00:01', 'v': 97.0}, {'date': '2015/01/01 00:02', 'v': 93.75}, {'date': '2015/01/01 00:03', 'v': 96.0}, {'date': '2015/01/01 00:04', 'v': 94.5}] csvfile = "example.csv" open(csvfile, "w") output:   writer = csv.writer(output, lineterminator='\n')   line in res:     date = line['date']     value = line['v']     writer.writerow([date, value]) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -