英文:
Read CSV in Python with date column
问题
我想将一个 CSV 文件加载到 Python 中。在这个 .csv 文件的 54 列中,我确定其中一些是日期列。
然而,在使用 pandas 在 Python 环境中读取 CSV 文件之后:
df = pd.read_csv("foo.csv", encoding="utf-8")
那些应该包含日期的列中,填充的是一些非常大的数字,例如 997513068000、1549627447000、1655482531000。
我最初认为这些可能是序数日期,可以使用 datetime.fromordinal() 将它们转换为日历日期。然而,这些数字太大了,不可能是序数日期。
你有关于日期列中这些大数字的含义以及如何将它们转换为正常日期的任何想法吗?
英文:
I want to load a csv into python. Out of the 54 columns in the .csv, I definetly now that some of those are date columns.
However, after reading the csv in the python environment with pandas
df = pd.read_csv("foo.csv", encoding="utf-8")
the colums that are supposed to have dates in it, are filled with really large numbers like 997513068000, 1549627447000, 1655482531000.
I first thought that those might be ordinal dates and I can convert them to calendar dates with datetime.fromordinal(). However, those numbers are way to large to be ordinal dates.
Any idea on what those large numbers in the date columns mean and how I can convert them to normal dates?
答案1
得分: 1
几乎可以确定这是一个纪元时间,可能是以毫秒为单位的。使用这个资源可以轻松地查看它在常规日期中的表示。
在代码中,使用Python的datetime模块的fromtimestamp()函数可以从纪元时间获取日期。
英文:
Almoast certainly this is an epoch time, likely in milliseconds. Use this resource to easily see what it is in a normal date.
In code, use the python datetime modules fromtimestamp() to get dates from epoch
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论