我需要在列中大写一些单词,但不是全部。
数据样本:
Name Dance
CHUNK Truffle Shuffle
DATA Gadget Shuffle
MOUTH Goin Shoppin
COREYH Aspirator shuffle
我尝试过的事情:
caps_list = ['CHUNK','DATA','MOUTH']
mask = df['Name'].apply(lambda x: x in caps_list)
df['Name'] = df['Name'].mask(mask).capitalize()
错误:
AttributeError: 'Series' object has no attribute 'capitalize'
答案 0 :(得分:3)
使用
df.Dance = np.where(df['Name'].isin(caps_list ),df.Dance.str.capitalize(),df.Dance)