Open aanranran opened 5 years ago
Hi,
I did not understand the problem, but you should check pandas documentation with example. From your code above " 1 MisleInjury.txt = pd.read_csv('MisleInjury.txt',encoding = "utf-8")". You are reading txt file using the argument pd.read_csv. I think you should use Open().
I hope the article below can enlighten you. https://www.pythonforbeginners.com/files/reading-and-writing-files-in-python
I think the problem you encountered is similar to the one Sailu previously posted. UTF-8 stands for 8-bit Unicode Transformation Format, the reason you encountered that is that there is something the computer may not able to interpret with the default system. Try to the "encoding" code, see if this helps.
Thanks everyone for your replies. I have solved my problem by changing my code as following:
MisleInjury = pd.read_csv(‘MisleInjury.txt’, encoding = "ISO-8859-1”, error_bad_lines=False, sep='\t’, header=None)`
This not only perfectly solved the error of ut-8 and tokenizing data but also spilt the text into columns. Hope my examples can provide additional feedbacks to other classmates who are in the same situation as me.
pd.dataframe=("datalink",encoding='latin-1')
I fail to input one of my databases in the JupyterNotebook when I use the code “read_csv" in pandas because of the following error:
UnicodeDecodeError Traceback (most recent call last) pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._convert_tokens()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._convert_with_dtype()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._string_convert()
pandas/_libs/parsers.pyx in pandas._libs.parsers._string_box_utf8()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 6: invalid continuation byte
During handling of the above exception, another exception occurred:
UnicodeDecodeError Traceback (most recent call last)