I am writing some code for a project and saving this code to .csv format. It then will be opened in excel to further inspect the data. There are 8 floats then 1 string in each row. How do I get excel to display each value in different cells? The code for the saving
def save_array():
t = utctime.t()
temp = data.get_data()
atime = np.append([temp],[t])
atime = ' '.join(atime)
return atime
with open( path2, 'w') as save_data:
save_data_write = csv.writer(save_data, delimiter = ' ' , dialect = 'excel')
save_data_write.writerow([save_array()])
save_data.close()
while i:
time.sleep(1)
with open( path2,'a') as save_data:
save_data_append = csv.writer(save_data, delimiter = ' ', dialect = 'excel')
save_data_append.writerow([save_array()])
save_data.close()
The saved data in excel looks like this.
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Apr 03 2017 20:24:59
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Apr 03 2017 20:25:00
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Apr 03 2017 20:25:01
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Apr 03 2017 20:25:02
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Apr 03 2017 20:25:03
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Apr 03 2017 20:25:04
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Apr 03 2017 20:25:05
This didn't copy very well but in excel this is all in the first cell and it also skips a line between rows. Does anybody know how to format this correctly?
Thanks
.csvfile with Excel just fine without anything fancy. First, use a comma for delimiting rather than a space. However, I don't understandsave_data_write.writerow([save_array()]), specificallysave_array().wbinstead ofw; this will get rid of your unwanted newlines between rows.