Python: Got \ xa0 instead of space in CSV and cannot remove or convert

I have a problem related to coding problem in python (IPython notebook). Since such problems are very common and simple, but I still can not fix it.

I have a CSV file, since you can see that we have many characters '\ xa0' and the other '\ n' in this file.

I used

with io.open(train_fname) as f:
for line in f:
    line = line.encode("ascii", "replace")

But it does not work, I always get the following output.

Imagine that you can say that you know what sanctions, no eternal rumors about IEAA rules, no longer hide \ xa0under \ xa0 the pretense of friendly nuclear energy. \ xa0 You have 2 days; \ Xa0i.e. \ xa0let in inspectors, stop killing civilians.

I tried other methods like

line.replace(u"\xa0", " ") , , CSV , . windows-1252, utf-8 , \xa0 - CSV .

\ xa0

CSV ? python? , replace, ? \Xa0 , ? , utf-8, ascii ?

, , , . , , . !

`

+4
2

\xa0, , : \ x a 0. ASCII, .

-, escape-. , . , \\. :

line.replace("\\xa0", " ")

line.replace(r"\xa0", " ")

r , .


, CSV . :

  • \n, , .
  • \\n , , , .
  • \xa0 - , ISO-8859-1.
  • \xc2\xa0 - , UTF-8.
  • \\xc2\\xa0 .
  • \\\\n.

, , escape- , . UTF-8. , . , Codepage 1252 ( ISO-8859-1).

+5

, \xa0, U + 00A0: NO-BREAK SPACE.

"\xa0"; \xa0 (.. Python "\\xa0") . ( , , .) string_escape, , :

for line in f:
    line = line.decode("string_escape")
+2

All Articles