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()
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()
You were trying to convert the dataframe altogether. Use this code:
for col in df.columns:
if df[col].dtype=='object':
df[col] = df[col].str.upper())
Hope that works! Because I have personally checked this right now..
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())