Skip to content Skip to sidebar Skip to footer

Replacing A Non Ascii Space Character In Python (pandas)

I'm working on with some identification numbers that are pulled from an excel spreadsheet. They are a mixture of numbers and strings. (manually maintained excel sheet) I loaded t

Solution 1:

Given the column contains a mixture of numbers and strings, you might be better off converting everything to a string and using pandas string manipulation methods on the column. For instance, to replace \xa0 with an empty string in the column:

exceldata['ID'] = exceldata['ID'].astype(str).str.replace(u'\xa0', '')
#                                ^^^^^^^^^^^^ potentially unnecessary, depending on the format of your data

This will replace the ID column with the string representation of the values, but with the \xa0 characters removed.

Post a Comment for "Replacing A Non Ascii Space Character In Python (pandas)"