【发布时间】:2019-09-30 05:05:05
【问题描述】:
我正在对一个包含多个输入错误的大型旧数据集进行排序。我想通过遍历一行来清理文档,以根据标准查找和更改类型错误。现在我在尝试删除 pandas 中的小时分秒时出现以下错误。
Out of bounds nanosecond timestamp: 3016-03-09 00:00:00
我的想法是这样的:
import pandas as pd
df = pd.read_excel(r'raw data.xlsx', header = 0)
for date in Dates:
if date is out of bounds date time:
replace str[0-3] with Year, inplace = True
df['Date'].dt.year,month,day
print(df)
典型的数据集输入错误可能是第 4 项中的日期
Item Description Date Year ...
1 Ketchup400 2015-10-27 00:00:00 2015 ...
2 Ketchup600 2018-02-16 00:00:00 2018 ...
3 Mustard800 2015-10-02 00:00:00 2015 ...
4 Mustard200 3016-03-09 00:00:00 2016 ...
1 Ketchup400 2018-02-26 00:00:00 2018 ...
... ... ... ... ...
我想从日期中删除小时、分钟和秒,更正日期并打印新文件...输出应该类似于:
Item Description Date Year ...
1 Ketchup400 2015-10-27 2015 ...
2 Ketchup600 2018-02-16 2018 ...
3 Mustard800 2015-10-02 2015 ...
4 Mustard200 2016-03-09 2016 ...
1 Ketchup400 2018-02-26 2018 ...
... ... ... ... ...
【问题讨论】:
标签: pandas date dataset missing-data