For the code down below I want to insert a Date column but it is not working. How would I be able to modify it so that I would be able to convert the unixtimestamp values into readable date values and then insert it into the 1st place as a column into the pandas dataframe?
import pandas as pd
import numpy as np
import time
A = [[1645586100000, 37702.5, 37703.5, 37702.0, 37703.5, 1.53230423],
[1645586160000, 37703.5, 37703.5, 37703.0, 37703.5, 1.37560196],
[1645586220000, 37703.5, 37703.5, 37696.0, 37696.0, 11.09279214],
[1645586280000, 37696.0, 37705.5, 37696.0, 37705.0, 9.96666858],
[1645586340000, 37705.0, 37705.5, 37705.0, 37705.0, 3.76670066],
[1645586400000, 37705.0, 37705.5, 37705.0, 37705.5, 1.99727182],
[1645586460000, 37705.5, 37705.5, 37687.0, 37687.0, 2.70162796]]
def Local_timezone(unix_timestamp):
utc_time = time.gmtime(unix_timestamp.astype(int))
local_time = time.localtime(unix_timestamp)
Output= time.strftime("%Y-%m-%d %H:%M:%S", local_time)
return Output
column_names = ["Unix","Open", "High","Low", "Close", "Volume"]
df = pd.DataFrame(A, columns=column_names)
Dates = Local_timezone(df["Unix"].to_numpy()/1000)
df.insert(1,"Date", Dates)
Error:
TypeError: only size-1 arrays can be converted to Python scalars
utc_time = time.gmtime(unix_timestamp.astype(int))