Categories
Development

Convert excel file with timestamp to python date and time

How can I convert a large .xlsx file which contains a lot of timestamps (i.e. 1537892885364) into date and time ( in python and then save it as a new .xlsx file?

I am new to python, and I tried lots of ways to achieve this today, but I did not find a solution.

Below is the code I used, but it gives me ‘[Errno 13] Permission denied’. I tried different ways which also gave problems.

from __future__ import absolute_import, division, print_function
import os
import pandas as pd

def main(path, filename, absolute_path_organisation_structure):
    absolute_filepath = os.path.join(path,filename)
    #Relevant list formed with 4th, 5th and 6th columns
    df = pd.read_excel(absolute_filepath, header=None, parse_cols=[4,5,6])
    # Transform column 0 and 2 to datetime
    df[0] = pd.to_datetime(df[0])
    df[2] = pd.to_datetime(df[2])
    print(df)

path = open(r'C:\\Users\\****\\data')
MISfile  = 'filename.xlsx'
main(path, MISfile,None)

Leave a Reply

Your email address will not be published. Required fields are marked *