pandas -对列的所有元素执行字符串操作 [英] pandas - perform string operation on all elements of a column
本文介绍了 pandas -对列的所有元素执行字符串操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在pandas数据框中有一个全为大写的列.我想将其更改为首字母大写的单词.
I have a column in a pandas dataframe that is all capitals. I would like to change this to words with only the first letter capitalized.
我尝试了以下操作:
import pandas as pd
data = pd.read_csv('my_file.csv')
data['field'] = data['field'].title()
这将返回错误:
'Series' object has no attribute 'title'
是否有一种简单的方法可以在pandas列上执行类似的字符串操作?
Is there a simple way to perform string operations like this on a pandas column?
推荐答案
在此处找到答案:
http://pandas.pydata.org/pandas-docs/stable/text.html
data['field'] = data['field'].str.title()
这篇关于 pandas -对列的所有元素执行字符串操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文