I have a DataFrame where the case of a particular column is inconsistent and I want to make it consistent:
In [1]: df = pd.DataFrame({"vals":["alpha","Beta","GAMMA"]})
In [2]: df
Out[2]:
vals
0 alpha
1 Beta
2 GAMMA
Is there is an easy, pythonic way to replace each value with the str.upper() of the string str ?
This should work for you:
df['vals'] = map(lambda x: x.upper(), df['vals'])
Or even:
df['vals'] = df['vals'].apply(lambda x: x.upper())
Ps.: in recent versions you may also:
df['vals'] = df['vals'].str.upper()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With