我有一个pandas dataframe,有一个纪元时间的索引,价格是这样的:
df = pd.DataFrame({'Index': [1547942400000, 1548028800000, 1548115200000], 'Price': [1170, 1170, 1170]})
# EDIT the index column in unnamed.我尝试过直接编辑索引,如下所示
df.index = dt.datetime.fromtimestamp(int(df.index) / 100).strftime('%Y-%m-%d')
# 100 to make it this year vs 1970s or 2040s 我还尝试使用apply(),它不能用于索引。我彻底地感到困惑和沮丧。我认为熊猫会让这样的事情变得微不足道。
感谢任何帮助,因为我希望在它上运行一个超级简单的自相关,看看我得到了什么。
发布于 2019-07-19 12:18:38
您可以使用下面的代码片段
df = pd.DataFrame({'Index': [1547942400000, 1548028800000, 1548115200000], 'Price': [1170, 1170, 1170]})
df.index = pd.to_datetime(df['Index'],unit='ms')
df
Index Price
Index
2019-01-20 1547942400000 1170
2019-01-21 1548028800000 1170
2019-01-22 1548115200000 1170https://stackoverflow.com/questions/57105229
复制相似问题