0

我试图弄清楚如何修复某些 ccxt 数据的时间戳到日期时间的转换。

这是我正在使用的数据:

    Timestamp   Open    High    Low Close   Volume
0   1506211200000   3779.54 3789.99 3622.76 3660.02 661.636390
1   1506297600000   3660.02 3979.87 3653.69 3920.75 727.994713
2   1506384000000   3928.00 3976.99 3850.05 3882.35 526.727987
3   1506470400000   3882.36 4249.94 3872.81 4193.00 628.170966
4   1506556800000   4192.11 4300.00 4101.00 4174.50 849.785325

这是我试图将“时间戳”列转换为的格式,但我似乎无法遍历并单独更改它们:

    Timestamp   Open    High    Low Close   Volume
0   2017-07-14 09:40:00 3779.54 3789.99 3622.76 3660.02 661.636390
1   2017-07-14 09:40:00 3660.02 3979.87 3653.69 3920.75 727.994713
2   2017-07-14 09:40:00 3928.00 3976.99 3850.05 3882.35 526.727987
3   2017-07-14 09:40:00 3882.36 4249.94 3872.81 4193.00 628.170966
4   2017-07-14 09:40:00 4192.11 4300.00 4101.00 4174.50 849.785325

我已经尝试了我能想到的一切,并且知道我把它复杂化了。

以下是我迄今为止尝试过的一些事情以及一些返回的错误:

df = pd.read_csv('binance-BTCUSDT-1d.csv', parse_dates=True)


# for ts in df['Timestamp']:
#      print(timestamp.strftime('%Y-%m-%d %H:%M:%S'))
# returns the same datetime for all cells


# df['Timestamp'] = timestamp.strftime('%Y-%m-%d %H:%M:%S')
# returns the same datetime for all cells



# datetime.fromtimestamp(df['Timestamp']).strftime('%Y/%m/%d %H:%M:%S')
# cannot convert series to int

# timestamp = datetime.fromtimestamp(df['Timestamp'].astype(int))
# cannot convert series to int

# time.strftime("%D %H:%M", time.localtime(int(df['Timestamp'])))
# cannot convert series to int

# utc_time = datetime.fromtimestamp(df['Timestamp'], timezone.utc)
# cannot convert series to int

# local_time = utc_time.astimezone()
# cannot convert series to int

# print(local_time.strftime("%Y-%m-%d %H:%M:%S.%f%z (%Z)"))
# cannot convert series to int


# dates = [datetime.fromtimestamp (x[0] // 1000) for x in df['Timestamp']]
# int object is not subscriptable


# datetime.fromtimestamp(x[0]//1000 for sec in df['Timestamp'].astype(int))
# int is required, got type generator


# print(timestamp.strftime('%Y-%m-%d %H:%M:%S'))

# DateTimeParse(ToString([df['Timestamp']]),"%Y%m%d%H%M%S")

# datetime.utcfromtimestamp(df['Timestamp']).strftime('%Y-%m-%dT%H:%M:%SZ')

# time.ctime(int(df['Timestamp']))

# datetime.fromtimestamp(float(df['Timestamp']/1000))

df.head()```


  [1]: https://i.stack.imgur.com/FwWyc.png
  [2]: https://i.stack.imgur.com/Rc1Jm.png
4

0 回答 0