![](/img/trans.png)
[英]pandas.to_datetime() how to convert from local timezone to UTC unix timestamp?
[英]Can pandas.to_datetime() format unix time to local timezone?
我試圖讓 pandas.to_datetime 給我與我的時區相關的正確時間,但我找不到任何關於如何做到這一點的信息。
這是我制作的代碼:
def _new_values_list(arg1=list()):
import time
keys = arg1[1]
sym = arg1[0]
"""
==========================================================================
:param: values returned by the seperate_key_value() in the form of a
variable. Probably something like candle_data, candleD, etc.
==========================================================================
:returns: a sorted pandas DataFrame with columns for the open, high, low
close, volume and datetime as index. It also, includes a row with the
epoch time for easier time series calculations.
==========================================================================
"""
o = []
for vals in keys: o.append(vals['open'])
h = []
for vals in keys: h.append(vals['high'])
l = []
for vals in keys: l.append(vals['low'])
c = []
for vals in keys: c.append(vals['close'])
etime = []
# for vals in keys: etime.append((vals['datetime'])/10000)
for vals in keys: etime.append(vals['datetime'])
time = []
for vals in keys:
vals = pd.to_datetime(vals['datetime'], unit='ms')
time.append(vals)
vol = []
for vals in keys: vol.append(vals['volume'])
df = pd.DataFrame({'unix_time':etime, 'datetime': time, 'open': o, 'high': h, 'low': l, 'close': c,'volume': vol})
return df
那么這是output:
unix_time datetime open high low close \
0 1637332200000 2021-11-19 14:30:00 342.71 343.0700 342.2000 342.810
1 1637332260000 2021-11-19 14:31:00 342.73 343.2000 342.7100 342.710
2 1637332320000 2021-11-19 14:32:00 342.76 342.8900 342.3101 342.875
3 1637332380000 2021-11-19 14:33:00 342.80 342.9965 342.6800 342.810
4 1637332440000 2021-11-19 14:34:00 342.86 343.1100 342.8600 343.080
... ... ... ... ... ... ...
3815 1638564900000 2021-12-03 20:55:00 321.68 322.4000 321.6100 322.320
3816 1638564960000 2021-12-03 20:56:00 322.30 322.7000 322.1600 322.450
3817 1638565020000 2021-12-03 20:57:00 322.42 323.0800 322.1100 323.050
3818 1638565080000 2021-12-03 20:58:00 323.05 323.0773 322.8500 322.950
3819 1638565140000 2021-12-03 20:59:00 322.96 323.4500 322.7300 323.180
volume std volume_std
0 1813225 0.242681 76462.813531
1 77239 0.242681 76462.813531
2 66437 0.242681 76462.813531
3 42748 0.242681 76462.813531
4 52295 0.242681 76462.813531
datetime 應該顯示為 08:30:00 但事實並非如此。
我可以改變它嗎? 如果是這樣怎么辦?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.