Applying uppercase to a column in pandas dataframe

后端 未结 3 1298
鱼传尺愫
鱼传尺愫 2020-12-09 07:37

I\'m having trouble applying upper case to a column in my DataFrame.

dataframe is df.

1/2 ID is the column head that need to apply

3条回答
  •  Happy的楠姐
    2020-12-09 08:17

    str.upper() wants a plain old Python 2 string

    unicode.upper() will want a unicode not a string (or you get TypeError: descriptor 'upper' requires a 'unicode' object but received a 'str')

    So I'd suggest making use of duck typing and call .upper() on each of your elements, e.g.

    df['1/2 ID'].apply(lambda x: x.upper(), inplace=True)
    

提交回复
热议问题