I wrote the below test code to check it is working properly and I get a "True" Value in the DF, but when i sure the same calculation on the just one value, it gives me "False". The correct value should be "False" as the date_time column is not in epoch/UNIX time
import pandas as pd
from datetime import datetime, timedelta
temp_list = []
i = 1
while i < 10:
d = {
'ticker': 'TEST',
'date_time': datetime.now() + timedelta(days=i),
'price': 100 + i,
'volume': i
}
temp_list.append(d)
i += 1
test_df = pd.DataFrame(data=temp_list)
test_df['isepoch'] = pd.notnull(pd.to_numeric(
test_df['date_time'], errors='coerce'))
print(test_df)
print(pd.notnull(pd.to_numeric(test_df['date_time'][0], errors='coerce')))
Output of the two print statements:
ticker date_time price volume isepoch
0 TEST 2021-09-16 10:33:43.285935 101 1 True
1 TEST 2021-09-17 10:33:43.285935 102 2 True
2 TEST 2021-09-18 10:33:43.285935 103 3 True
3 TEST 2021-09-19 10:33:43.285935 104 4 True
4 TEST 2021-09-20 10:33:43.285935 105 5 True
5 TEST 2021-09-21 10:33:43.285935 106 6 True
6 TEST 2021-09-22 10:33:43.285935 107 7 True
7 TEST 2021-09-23 10:33:43.285935 108 8 True
8 TEST 2021-09-24 10:33:43.285935 109 9 True
False
I adapted the solution from Pandas: Check if value is epoch time using python, to create the 'isepoch' column in the dataframe.