草庐IT

datetimelike

全部标签

python - AttributeError : Can only use . 具有 datetimelike 值的 dt 访问器

您好,我正在使用pandas将列转换为月份。当我读取我的数据时,它们是对象:Dateobjectdtype:object所以我首先将它们设为日期时间,然后尝试将它们设为月份:importpandasaspdfile='/pathtocsv.csv'df=pd.read_csv(file,sep=',',encoding='utf-8-sig',usecols=['Date','ids'])df['Date']=pd.to_datetime(df['Date'])df['Month']=df['Date'].dt.month如果有帮助的话:In[10]:df['Date'].dtypeO