I have tried many ways to have this done, but I'm still getting errors. What I am doing wrong?
If I attempt to get this done with just simple string, everything goes ok:
import pytz
from datetime import datetime
id_board = '608332c0'
df_final = datetime.fromtimestamp(int(id_board,16))
print(df_final)
output: 2021-04-23 14:49:04
However, I do have a list I would like to get the datestamp, here is where the code that gives me errors:
import pytz
import pandas as pd
from datetime import datetime
df_final = pd.read_csv("Book1.csv")
print(df_final)
Card ID # of Members
0 608332c0806da55df13b498b 2
1 60819c7ccd3a695b79f54f53 5
2 60817b9df8f5422bbaf2cff9 9
3 60806f3d24f11404f1470904 2
4 607ed78a89de73411e937655 1
5 608332e6943e7263a56fb3ff 2
x = df_final["Card ID"].str[0:8]
df_final["Created Date"] = x
print(df_final)
Card ID # of Members Created Date
0 608332c0806da55df13b498b 2 608332c0
1 60819c7ccd3a695b79f54f53 5 60819c7c
2 60817b9df8f5422bbaf2cff9 9 60817b9d
3 60806f3d24f11404f1470904 2 60806f3d
4 607ed78a89de73411e937655 1 607ed78a
5 608332e6943e7263a56fb3ff 2 608332e6
df_final["Created Date"] = datetime.fromtimestamp(int(x,16))
print(df_final)
Traceback (most recent call last):
File "c:\Users\xxxxx\Desktop\Manual Formulas 1\hexa.py", line 17, in <module>
df_final["Created Date"] = datetime.fromtimestamp(int(x,16))
TypeError: int() can't convert non-string with explicit base
I have tried many "fixes" I have read but still the same. I also tried with a loop over the rows but got the following error:
invalid literal for int() with base 16
Thanks for your help! Joe.