Aghyad Skaif
Aghyad Skaif

Reputation: 49

reformatting the timestamp in my dataset to have it as datetime

I want to reformat the timestamp in my dataset to have it as a date + time.

here is my dataset

[1]: https://i.sstatic.net/kYLEA.png

and I tried this

data1 = pd.read_excel(r"C:\Users\user\Desktop\Consumption.xlsx")

data1['Timestamp']= pd.to_datetime(['Timestamp'], unit='s')

and I got this error

ValueError: non convertible value Timestamp with the unit 's'

I also tried not to pass the "unit" in the pd.to_datetime function and it gave an error The type of time stamp is Object. Please any help.

Upvotes: 0

Views: 664

Answers (3)

Yana
Yana

Reputation: 975

I would suggest you check the documentation of the function here

If you want to add date-time, you can format like this:

  • format='%d/%m/%Y %H:%M:%S'

Upvotes: 1

gtomer
gtomer

Reputation: 6564

Try this:

data1['Date'] = pd.DataFrame(data1['Timestamp'], format ='%d/%m/%Y')

Upvotes: 0

jezrael
jezrael

Reputation: 862406

Format of datetimes is not unix time, so raised error. You can split values by ; and select second lists by str[1] and then convert to datetimes:

data1['Timestamp']= pd.to_datetime(data1['Timestamp'].str.split(';').str[1])

Upvotes: 1

Related Questions