首页 > 解决方案 > 使用 pandas 从 Excel 工作表中的列中提取数据

问题描述

在我的 Excel 表中有一个类型为“InvoiceDate”的列datetime64。我正在尝试从此列中提取日期并为其分配一个新列。

下面是我的 python 代码以及数据表的图像。它输出警告,但操作已成功完成。

代码:

df1["InvoiceMonth"] = df1["InvoiceDate"].dt.date

错误:

C:\Users\anaconda3\lib\site-packages\ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value

数据

标签: python-3.xexcelpandas

解决方案


推荐阅读