Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas - perform string operation on all elements of a column

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.

I have tried the following:

import pandas as pd
data = pd.read_csv('my_file.csv')

data['field'] = data['field'].title()

This returns the error:

'Series' object has no attribute 'title'

Is there a simple way to perform string operations like this on a pandas column?

like image 217
datavoredan Avatar asked Dec 15 '22 07:12

datavoredan


1 Answers

Found the answer here:

http://pandas.pydata.org/pandas-docs/stable/text.html

data['field'] = data['field'].str.title()
like image 106
datavoredan Avatar answered Mar 02 '23 15:03

datavoredan