熊猫给出日期时间.date'被强制到日期时间



我试图比较两个日期值。我的数据包含日期列。

dateCols = ['Document Date']
data = pd.read_excel(os.path.join(delivery_file_path, f), parse_dates=dateCols,
dayfirst=True, sheet_name='Refined',skiprows=1)
data['Document Date'] = pd.to_datetime(data['Document Date'])
df = pd.DataFrame(columns=['Document Date'], data=data['Document Date'])
print(df.dtypes)  <-- prints **datetime64[ns]**
if (df['Document Date'] >= start) and (df['Document Date'] <= end):
.....

我收到以下错误;

datetime.date' is coerced to a datetime. In the future pandas will
not coerce, and a TypeError will be raised. To retain the current
behavior, convert the 'datetime.date' to a datetime with
'pd.Timestamp'.
if (df['Document Date'] >= start) and (df['Document Date'] <= end):
...
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

我的上述日期比较有什么问题?

我整理得像添加 .any((

if ((df['Document Date'] >= start) & (df['Document Date'] <= end)).any():

我的要求是,我处理的文件是否包含每月价值记录。它用于数据质量检查。所以使用 any(( 就可以了。

最新更新