Python CSV output two rows instead of two column -
i outputing dictionary, see code below. but, out creates 2 rows. instead of 2 columns.
with open("<location of file>"+str(report_date)+".csv", 'w') f: w = csv.writer(f) w.writerow(output_list.keys()) w.writerow(output_list.values())
excel output:
col 1 row 1, col 2, row 1, col 3 row 1 col 1 row 2, col2 row 2, col 3, row 2
i see output 2 columns:
column 1 way down dictionary keys
column 2 way down dictionary values
you outputting 2 rows because telling output 2 rows. writerow
if call twice. need iterate on individual items if want output 1 row per item:
w = csv.writer(f) item in output_list.items(): w.writerow(item)
item
two-element tuple contains key , value.
wiki
Comments
Post a Comment