I import csv table into JUPYTER NOTEBOOK, and something wrong is happening when I try to iloc
a video views column (К-ть переглядів).
I need to format this cell to INT type (using .astype()
), but it tells me that there is an error:
ValueError: invalid literal for int() with base 10: ‘380xa0891xa0555’
Can anyone please tell me what is wrong?
Advertisement
Answer
This is a non breaking space (chr(160)
). Use str.replace
to remove them.
JavaScript
x
14
14
1
>>> df['A']
2
0 380 891 555
3
Name: A, dtype: object
4
5
>>> df['A'].dtype.name
6
'object'
7
8
>>> df['A'].astype(int)
9
ValueError: invalid literal for int() with base 10: '380xa0891xa0555'
10
11
>>> df['A'].str.replace(chr(160), '').astype(int)
12
0 380891555
13
Name: A, dtype: int64
14