あなたはto_datetime(..., unit='s')
を使用することができます
In [158]: df = pd.DataFrame({'epochtime': pd.date_range('2001-01-01', freq='1S', periods=10**5)}).astype(np.int64)//10**9
In [159]:
In [159]: df.head()
Out[159]:
epochtime
0 978307200
1 978307201
2 978307202
3 978307203
4 978307204
In [160]:
In [160]: len(df)
Out[160]: 100000
In [161]:
In [161]: %timeit df['datetime'] = pd.to_datetime(df['epochtime'], unit='s')
100 loops, best of 3: 16.9 ms per loop
In [162]:
In [162]: %%timeit
.....: for i in range(len(df)):
.....: df['datetime'].iloc[i] = datetime.fromtimestamp(df2['epochtime'].iloc[i])
.....:
c:\envs\py35\lib\site-packages\pandas\core\indexing.py:128: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
self._setitem_with_indexer(indexer, value)
1 loop, best of 3: 54.5 s per loop
結論: @Natecat、 あなたは(16.9 ms
対54.5 s
datetime.fromtimestampを見ることができるように)は基本的にC言語で実装されていますあなたがdatetimeオブジェクトでそれを望むなら、それを得ることができるからです。 – Natecat
@ネイトキャット、もしそれが簡単なら、誰もパンダを使わないだろう;) – MaxU