1. Problem description
When learning from books, I find that the data set downloaded from GitHub
will report an error when reading with pandas
:
2. Solutions
It is obviously a coding problem. Use the file
command to view the file code:
ISO-8859
the code in Python
is iso-8859-1
, which can be judged by the following function:
pip install chardet
def get_encoding(file):
with open(file, 'rb') as f:
return chardet.detect(f.read())['encoding']
Therefore, use the encoding
parameter to specify the actual file format.
it’s fine too
movies = pd.read_table('movies.dat', encoding=get_encoding('movies.dat'), sep='::', header=None, names=mnames, engine='python')
Similar Posts:
- [C language] Multi-file compilation under linux
- Python Pandas: Read_Excel() and to_Excel() function
- JavaWeb HttpServletRequest (How to Get Line, Header and Body)
- Python: How to Read file initialization from file failed by panda
- MySQL Reading table information for completion of table and column names
- Python: How to Batch Read the Form Information in Word and output them to Excel file
- Python pandas.read_ Oserror: initializing from file failed
- [Solved] react native TypeError: Network request failed Unable to symbolicate stack trace: The stack is null
- JAVA: scanner Read File encoding Error noSuchElementException
- [Solved] Scrapy Error: ERROR: Error downloading & RequestGenerationFailed