Python Forum
Python date format changes to date & time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python date format changes to date & time
#1
Hi, my original data is short date (15/10/2023) but when I run the below code python changes it to 2023-10-15 00:00:00, how can I prevent this? Cheers.
import pandas as pd 

inspdata=pd.read_excel('Inspections data.xlsx')

#remove columns 
inspdata.drop(['Notice Creation','count()'],axis=1, inplace=True)

#replace header row names
inspdata.columns=['EForm ID','Contractor','Address','Area','Classification','Program','Notice Ref #','Category','Inspection Type',
'Result','Actual Date','Created Date','Status','CIO','PO']

#delete first 4 rows below the header
inspdata.drop([0,1,2,3],axis=0,inplace=True) #keeps header row

#replace text
inspdata['Classification'].replace(['VACQREP','VACAP'],['VAC','VAC'],inplace=True)

print(inspdata.head(10))

inspdata.to_excel('Inspections Data Python.xlsx',index=False)
Reply
#2
There is an option in the ExcelWriter to set the datetime format.

https://pandas.pydata.org/docs/reference...xcelWriter

From your other posts it looks like you will become an expert ExcelWriter user. I found this a nice intro.

https://sparkbyexamples.com/pandas/panda...-examples/
1418 likes this post
Reply
#3
Hi Deanhystad, thanks for responding.

I will always be modifying data so I assume I will need Openpyxl not xlsxwriter...is that correct, cheers
Reply
#4
Are you referring to this: "By default, it uses xlsxwriter if it is installed otherwise it uses openpyxl"

I think either will work fine. You'll modify the data in pandas. You only use xlsxwriter or openpyxl to write the pandas dataframe to an excel file.
1418 likes this post
Reply
#5
I obviously need to do a lot more research on what libraries I need, cheers
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 251 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Date Time Series Help...Please spra8560 2 381 Feb-01-2024, 01:38 PM
Last Post: spra8560
  Create dual folder on different path/drive based on the date agmoraojr 2 458 Jan-21-2024, 10:02 AM
Last Post: snippsat
  Downloading time zone aware files, getting wrong files(by date))s tester_V 9 1,059 Jul-23-2023, 08:32 AM
Last Post: deanhystad
  Formatting a date time string read from a csv file DosAtPython 5 1,302 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  PDF properties doesn't show created or modified date Pedroski55 4 1,102 Jun-19-2023, 08:09 AM
Last Post: Pedroski55
  How should I run pip-date in python3? newbieAuggie2019 5 1,901 Mar-31-2023, 03:21 PM
Last Post: snippsat
  How to see the date of installation of python modules. newbieAuggie2019 4 1,641 Mar-31-2023, 12:40 PM
Last Post: newbieAuggie2019
  Review my code: convert a HTTP date header to a datetime object stevendaprano 1 2,010 Dec-17-2022, 12:24 AM
Last Post: snippsat
  Return the [Date] that within the last 14 days bnadir55 5 1,183 Dec-08-2022, 03:38 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020