'\ufeff' in python - ValueError: could not convert string to float: '\ufeff524.794072' resolved

Solve the extra characters appearing in the python list

When reading the csv file with python, it is found that different data files, the first number in the list will have the redundant character '\ufeff' (as shown in the figure below), which will cause an error to fail to run. Note: there are no errors such as redundant spaces and line breaks. , so using strip(), strip('\t') will not work

Solution:
This is an error caused by an encoding problem. You can try to change the encoding method or manually remove illegal characters: path_dir = file.readline().strip('\ufeff') (
Just specify to remove these characters directly, because It has always been these characters), and I have solved it by manually removing these characters (as shown in the figure below)

insert image description here

Guess you like

Origin blog.csdn.net/qq_41968196/article/details/125317030