keenQuestions
keenQuestions

Reputation: 35

How to make one column upper case in pandas and return all other columns?

Error at the moment, now I want to return all the columns and data but just make one column need to be upper.

hellodf= hellodf.loc[hellodf['ContactName'].str.upper()]

Upvotes: 0

Views: 1628

Answers (2)

jezrael
jezrael

Reputation: 862481

Use Series.str.isupper for filter:

hellodf= hellodf.loc[hellodf['ContactName'].str.isupper()]

If need convert one column to uppercase:

hellodf['ContactName'] = hellodf['ContactName'].str.upper()

Upvotes: 2

Anand Sowmithiran
Anand Sowmithiran

Reputation: 2920

Use the Series.str.upper() function to make the strings in a certain column to uppercase. Below is the actual code that works,

other=hellodf['ContactName'].str.upper()

#convert the series to a DF
other=pd.DataFrame(other) 

newdf=hellodf.join(other,rsuffix='_upper')

#to drop the initial coulmn, and retain only the uppercased column
newdf=newdf.drop(['ContactNname'], axis=1)

Upvotes: 0

Related Questions