3
嗨我試圖將時區設置爲數據幀,然後將其更改爲UCT時區。設置時區爲熊貓數據幀
我讀的數據是:
Date Time;G_h
2012-03-31 23:00:00.000;0
2012-03-31 23:15:00.000;0
2012-03-31 23:30:00.000;0
2012-03-31 23:45:00.000;0
2012-04-01 00:00:00.000;0
2012-04-01 00:15:00.000;0
2012-04-01 00:30:00.000;0
2012-04-01 00:45:00.000;0
2012-04-01 01:00:00.000;0
2012-04-01 01:15:00.000;0
2012-04-01 01:30:00.000;0
我使用此代碼
df = pd.read_csv('input.csv', sep=";", index_col='Date Time', decimal=',')
df.index = pd.to_datetime(df.index, unit='s')
我的想法是使用此代碼:如果我嘗試
df.index.tz_localize('Europe/Rome').tz_covert('UTC')
用此代碼設置時區'Europe/Rome'
df.index=df.index.tz_localize('Europe/Rome')
我得到這樣的結果:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2820, in run_code
exec code_obj in self.user_global_ns, self.user_ns
File "<ipython-input-38-0aa69957bc90>", line 1, in <module>
d.index.tz_localize('Europe/Rome')
File "/usr/local/lib/python2.7/dist-packages/pandas/tseries/index.py", line 1608, in tz_localize
new_dates = tslib.tz_localize_to_utc(self.asi8, tz, infer_dst=infer_dst)
File "tslib.pyx", line 1981, in pandas.tslib.tz_localize_to_utc (pandas/tslib.c:29912)
AmbiguousTimeError: Cannot infer dst time from Timestamp('2012-10-28 02:00:00', tz=None), try using the 'infer_dst' argument
什麼建議嗎?
我確定輸入文件中的時間設置正確,dst正常!
我仍然得到同樣的錯誤了。 –
你有什麼熊貓版本? – MaxU
In [13]:pd .__ version__ Out [13]:'0.13.1' –