0

I'm using the csv module to export data from a large number of raw data files in csv format into an excel template. I'm having an issue with how the dates are being exported, trying to plot a graph from the dates gives the following where the x axis shows only 00:00 rather than the changing times. Dates are in format dd/mm/yyyy hh:mm.

Excel date graph

I'm using this code with openpyxl and csv:

from openpyxl import Workbook
import csv

wb = Workbook()
ws = wb.active

with open('Date Test.csv') as f:
    reader = csv.reader(f, delimiter='\t')
    for row in reader:
        ws.append(row)

wb.save('excel date.xlsx')
APhillips
  • 1,175
  • 9
  • 17
James
  • 45
  • 7
  • 1
    https://stackoverflow.com/questions/46354065/how-to-preserve-date-format-when-creating-an-excel-file – venkatadileep Jan 21 '20 at 15:13
  • 1
    ReadTheFineManual [using-number-formats](https://openpyxl.readthedocs.io/en/stable/usage.html#using-number-formats). Keep in mind `CSV` is **TEXT** only. – stovfl Jan 21 '20 at 15:18
  • What is shown in Excel file for the dates? It may depend on your locale settings... – Serge Ballesta Jan 21 '20 at 15:21
  • CSV has no typing or formatting. You have to decide how you want to do this yourself. This, and encoding problems, make CSV unsuited for generic data transfer. – Charlie Clark Jan 21 '20 at 19:00

0 Answers0