I'm having trouble applying upper case to a column in my DataFrame.
dataframe is df.
df
1/2 ID is the column head that need to apply UPPERCASE.
1/2 ID
The problem is that the values are made up of three letters and three numbers. For example rrr123 is one of the values.
rrr123
df['1/2 ID'] = map(str.upper, df['1/2 ID'])
I got an error:
TypeError: descriptor 'upper' requires a 'str' object but received a 'unicode' error.
How can I apply upper case to the first three letters in the column of the DataFrame df?
This should work:
df['1/2 ID'] = map(lambda x: str(x).upper(), df['1/2 ID'])
and should you want all the columns names to be in uppercase format:
columns
df.columns = map(lambda x: str(x).upper(), df.columns)
2.1m questions
2.1m answers
60 comments
56.8k users