Editing timeslot for SQL in Python

I have an excel file that consists of hourly basis values, date and time as timeslot.

here how it looks like, it goes on until present date

I want to import this excel to PostgreSQL DB, but I need to edit the date and time before. Otherwise its giving error.

Editing that date and time in excel also okay but I think doing it in python would be much easier.

I want to transform that date and time into this timeslot:

2018-05-27 00:00:00 

1 answer

  • answered 2020-06-02 15:08 automatickebab

    I solve it like this, and it worked. Someone may wonder about the solution.

    import pandas as pd
    from xlwt import Workbook
    from datetime import datetime
    df = pd.read_excel('yourexcell file.xlsx')
    for i in df.index:
        start_date = df['date'][i] #date column name in excel file 
        start_time=df['time'][i] #time column name in excel file
        date_time = datetime.strptime(start_date, "%d.%m.%Y")
    #dateandtime combined and ready.
    wb = Workbook()
    sheet = wb.add_sheet('Sheet 1')
    for k in range(len(date)):
    print("csv file saved.")

    and here it is: output 2018-05-27 00:00:00