0

I have a .xlsx file that I want to convert to .csv file. I have done a demo file as shown in the screenshot. In the .xlsx file, I have 3 sheets and I want to keep the last sheet only. In addition, I want to preserve my dates in a MM/DD/YYYY format.

enter image description here

Found a few solutions here and there on converting then dropping sheets or vice versa. The closest I have come to is using the solution from this link :

But it doesn't keep the date format of MM/DD/YYYY and instead converts it to numbers e.g. 44079. Tried searching solution to convert the numbers to date but there is nothing on this.

Can anyone help me with this? I can provide more clarification if needed.

I am coding in Python.

Ron Rosenfeld
  • 53,870
  • 7
  • 28
  • 60
Newbee Coding
  • 149
  • 2
  • 9

1 Answers1

0

Hi I solved my own question by using the answer from this Python using pandas to convert xlsx to csv file. How to delete index column?

In addition, because the date is converted into something, not I want in the converted .csv filee.g.

05-09-2020 00:00:00

I used pandas and load the converted csv file to a dataframe. From there I used df['date made'] = pd.to_datetime(df['date made']) to convert the date from an object to datetime. After that I used df['date made'] = df['date made'].dt.strftime(%m/%d/%Y) to get

09/05/2020

which is the date format I wanted. I repeat the steps for Date Due as well.

Hope this helps those who are looking to convert .xlsx to .csv and do some formatting on the date.

Newbee Coding
  • 149
  • 2
  • 9