0

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 Answers1

0

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')
date=[]

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")

    comb=datetime.combine(date_time,start_time)

    date.append(comb)
#dateandtime combined and ready.


wb = Workbook()
sheet = wb.add_sheet('Sheet 1')

for k in range(len(date)):
    sheet.write(k,0,date[k])
wb.save('datetime_generated'+".CSV")
print("csv file saved.")

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