my code:
if df.dtypes=='object':
df.applymap(lambda x: x.upper())
Error: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
A df.dtypes
is not a scalar if your DataFrame
has more than one columns. So it fails the condition test if df.dtypes=='object'
.
Try the following code:
for c in df.columns:
if df[c].dtype=='object':
df[c] = df[c].apply(lambda x: x.upper())