简体   繁体   English

将列转换为日期时间格式时显示超出范围的纳秒时间戳错误

[英]Showing out of bounds nanosecond timestamp error when converting column to datetime format

I am using the dataset- Meteorite Landings which can be found here- https://www.kaggle.com/nasa/meteorite-landings#meteorite-landings.csv我正在使用数据集- Meteorite Landings,可以在这里找到- https://www.kaggle.com/nasa/meteorite-landings#meteorite-landings.csv

A snap of the data: https://imgur.com/a/CrwL3h6数据快照: https://imgur.com/a/CrwL3h6

The dataset has a 'year' column which I renamed to 'year1'数据集有一个“年份”列,我将其重命名为“year1”

data = data.rename(columns = {"year":"year1"}) 

The year1 column is given:给出year1列:

0        01/01/1880 12:00:00 AM
1                 1/1/1951 0:00
2                 1/1/1952 0:00
3                 1/1/1976 0:00
4                 1/1/1902 0:00
                  ...          
45711             1/1/1990 0:00
45712             1/1/1999 0:00
45713             1/1/1939 0:00
45714             1/1/2003 0:00
45715             1/1/1976 0:00
Name: year1, Length: 45716, dtype: object

I want to convert this column to datetime format in order to only keep the year as the date and time are repeated values, which is of no use, moreover the column's name is 'year'.我想将此列转换为日期时间格式,以便仅保留年份,因为日期和时间是重复值,这是没有用的,而且列的名称是“年”。

I used this:我用这个:

data['year1'] = pd.to_datetime(data['year1'])

It shows an error when I try to do so:当我尝试这样做时它显示一个错误:

OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1583-01-01 00:00:00

In order to solve this, I tried using this:为了解决这个问题,我尝试使用这个:

data['year1'] = pd.to_datetime(data['year1'],errors='coerce')

but on doing so, even then the year1 column is not in datetime format.但这样做时,即使那样 year1 列也不是日期时间格式。

What can I do to convert it into datetime format?我该怎么做才能将其转换为日期时间格式?

Sample Data:样本数据:

                name   id nametype     recclass      mass  fall    year    reclat    reclong               GeoLocation
              Aachen    1    Valid           L5      21.0  Fell  1880.0  50.77500    6.08333     (50.775000, 6.083330)
              Aarhus    2    Valid           H6     720.0  Fell  1951.0  56.18333   10.23333    (56.183330, 10.233330)
                Abee    6    Valid          EH4  107000.0  Fell  1952.0  54.21667 -113.00000  (54.216670, -113.000000)
            Acapulco   10    Valid  Acapulcoite    1914.0  Fell  1976.0  16.88333  -99.90000   (16.883330, -99.900000)
             Achiras  370    Valid           L6     780.0  Fell  1902.0 -33.16667  -64.95000  (-33.166670, -64.950000)
            Adhi Kot  379    Valid          EH4    4239.0  Fell  1919.0  32.10000   71.80000    (32.100000, 71.800000)
 Adzhi-Bogdo (stone)  390    Valid        LL3-6     910.0  Fell  1949.0  44.83333   95.16667    (44.833330, 95.166670)
                Agen  392    Valid           H5   30000.0  Fell  1814.0  44.21667    0.61667     (44.216670, 0.616670)
              Aguada  398    Valid           L6    1620.0  Fell  1930.0 -31.60000  -65.23333  (-31.600000, -65.233330)
       Aguila Blanca  417    Valid            L    1440.0  Fell  1920.0 -30.86667  -64.55000  (-30.866670, -64.550000)

Pandas refuses to work with datetimes earlier than 1677. But no matter, because your input CSV file has the year column as exactly that: the year alone. Pandas 拒绝使用早于 1677 的日期时间。但没关系,因为您输入的 CSV 文件具有完全相同的year列:仅年份。 So just stop doing whatever you're doing that converts the year column into datetimes, and load it as a plain integer column.因此,只需停止将year列转换为日期时间的任何操作,并将其加载为普通的 integer 列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 超出范围的纳秒级时间戳 - Out of bounds nanosecond timestamp 从 CSV 导入时转换日期,OutOfBoundsDatetime:超出范围纳秒时间戳。 Pandas - Converting dates when importing from CSV, OutOfBoundsDatetime: Out of bounds nanosecond timestamp. Pandas OutOfBoundsDatetime:越界纳秒时间戳 - OutOfBoundsDatetime: Out of bounds nanosecond timestamp “超出纳秒时间戳”? 你如何避免这个错误? - "Out of bounds nanosecond timestamp"? How do you avoid this error? 在 python 中使用 fillna 时出现越界纳秒时间戳错误? - Getting Out of bounds nanosecond timestamp error while using fillna in python? Python Pandas to_datetime pandas.datetime的出纳秒时间戳 - Python Pandas to_datetime Out of bounds nanosecond timestamp on a pandas.datetime 如何解决Python Pandas DataFrame的“ Outbounds nanosecond timestamp”错误? - How to work around Python Pandas DataFrame's “Out of bounds nanosecond timestamp” error? 超出范围的纳秒级时间戳记:1-01-01 00:00:00 - Out of bounds nanosecond timestamp: 1-01-01 00:00:00 Dask 将时间戳列转换为日期时间时出错 - Dask Getting Error converting timestamp column to datetime 长数据框的Python Pandas超出日期时间时间戳错误 - Python Pandas out of bounds datetime timestamp error for long dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM