Forum Discussion

83dons's avatar
83dons
Helper III
1 year ago
Solved

Date field not pulling into CSV in Python

Hi I am using the following python code to convert a table to a CSV that has inverted commas round every field. It is working apart from for date fields where I get I get "Microsoft.OleDb.Date" instead of expected e.g. "01/02/2023". ANy ideas if this can be fixed using the below coding rather than have to create new columns for every date field of different type ie text instead of date. This converter should be able to process a date field I would have thought.

 

import pandas as pd
dataset.to_csv(
r"REMOVED",
sep=',',
quotechar='"',
quoting=1,
index=False,
na_rep='',
encoding='utf-8'
)

  • I think it is actually easier to just create a new column of type text from the date column then remove the original and rename the new column. That then pulls through ok using the dataset to CSV function.