I have a column in a csv file which has Unicode values (\x) written as normal text. I have the following code (not mine) which im trying to use to decode this text but it is throwing a syntax error when trying to use it.
with open("fixed_datasetssscopy.csv", "r") as fp:
file_buffer = io.StringIO()
for line in fp.read().splitlines():
file_buffer.write(eval('''b"{}".decode('utf-8')'''.format(line)))
file_buffer.write('\n')
file_buffer.seek(0)
df = pandas.from_csv(file_buffer)
When looking at the entries that throw the errors they are encased in quotes "" when I print them in my IDE, even though in the CSV file itself they are not. An example of some entries that give the errors are below.
ER...in the end it's a job. So, fair dos. https:/asdasd
When i started using Gutenberg like a month ago, I didn't care for the workflow but now it makes it easy to do thin\xe2\x80\xa6 https:/asdasd
The actual error message is:
Traceback (most recent call last):
File "C:/Users", line 8, in <module>
file_buffer.write(eval('''b"{}".decode('utf-8')'''.format(line)))
File "<string>", line 1
b""ER...in the end it's a job. So, fair dos. https://u",,,,,,,,,".decode('utf-8')
^
SyntaxError: invalid syntax
How can I fix this error ?