环境是Python+pandas,以下代码,是先对['派单日期'] 进行时间格式,再多条件drop,删除2020年之前的。
['派单日期']的格式是:2020-12-12 10:23:22
[Python] 纯文本查看 复制代码
import os
import numpy as np
import pandas as pd
from openpyxl import Workbook
# 格式化日期
sheetOnTheWay['派单日期'] = pd.to_datetime(sheetOnTheWay['派单日期'])
# 清洗不需要的行
sheetOnTheWay = sheetOnTheWay.drop(sheetOnTheWay[sheetOnTheWay['备注'].str.contains('测试') & sheetOnTheWay['派单日期'].year > 2020].index)
但以上代码报错,提示列没有属性year,这个怎么改?谢谢。
[Python] 纯文本查看 复制代码 Traceback (most recent call last):
File "D:/python/pyJieDuanTongBao/pyJieDuanTongBao.py", line 118, in <module>
sheetOnTheWay = sheetOnTheWay.drop(sheetOnTheWay[sheetOnTheWay['备注'].str.contains('测试') & sheetOnTheWay['派单日期'].year != 2020].index)
File "D:\Program Files\anaconda\envs\playData\lib\site-packages\pandas\core\generic.py", line 5139, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'year' |