applymap(lambda x: x.encode('unicode_escape'). decode('utf-8') if isinstance(x, str) else x) 1

applymap(lambda x: x.encode(‘unicode_escape’). decode(‘utf-8’) if isinstance(x, str) else x)

dataframe = dataframe.applymap(lambda x: x.encode('unicode_escape').
                 decode('utf-8') if isinstance(x, str) else x)

Here is what the above code is Doing:
1. We are using the applymap function to apply a lambda function to all the columns of the dataframe.
2. The lambda function is checking if the value is a string or not. If it is a string, then it is encoded to unicode escape and then decoded to utf-8.
3. If the value is not a string, then it is returned as it is.

Similar Posts