UnicodeEncodeError: 'ascii' codec can't encode characters in position 321-322: ordinal not in range(128)

Viewed 758

I am trying to join column values in xlsx file using pandas. I am using the below code to that.

(df.astype(str).groupby('name', as_index=False, sort=False)
             .apply(lambda x: pd.Series({v: ','.join(x[v].unique()) for v in x})))

But, I am getting error like

UnicodeEncodeError: 'ascii' codec can't encode characters in position 321-322: ordinal not in range(128)
1 Answers

If you only need string for your DataFrame, you can use the option dtype = unicode in your read_excel function and remove the astype(str).

Related