Python 在数据帧中切片对象类型的值

Python 在数据帧中切片对象类型的值,python,pandas,data-cleaning,Python,Pandas,Data Cleaning,我有一个数据框,其中列中的所有值都显示发布日期 我需要删除一个附加文本以获得以下结果: Identifier int64 Edition Statement object Place of Publication object Date of Publication object Publisher object Title object Author

我有一个数据框,其中列中的所有值都显示发布日期

我需要删除一个附加文本以获得以下结果:

Identifier               int64
Edition Statement       object
Place of Publication    object
Date of Publication     object
Publisher               object
Title                   object
Author                  object
Contributors            object
Flickr URL              object
dtype: object
发件人:

1879[1879]

1879年

我已经检查了数据类型,并得到以下结果:

Identifier               int64
Edition Statement       object
Place of Publication    object
Date of Publication     object
Publisher               object
Title                   object
Author                  object
Contributors            object
Flickr URL              object
dtype: object
最后,我尝试了以下方法,但对我无效

new_books = books['Date of Publication'].astype(object).apply(lambda x: x.str.slice(0, 3))

我做错了什么?

不要将您的呼叫包装在应用程序中,而只需对序列本身进行操作:


您只需对序列本身进行操作,而不是将呼叫包装在apply中: