pandas.read_csv() 报错 OSError: Initializing from file failed

pandas.read_csv () reports OSError: Initializing from file failed, generally caused by two situations: one is that the function parameter is a path instead of the file name, and the other is that the function parameter is in Chinese.
The first case is simple, because the file name is not placed after the path, and the file name is added after the path. You can also switch the folder to the folder where the target file is located in the code. The process is too complicated and it is not recommended or recommended, so it will not be displayed.
In the second case, even if the path and file name are complete, the reason for the error is that there is Chinese in this parameter, but does Python3 already support Chinese? Referring to the cause of the error and the source code of pandas, it is found that when calling read_csv () method of pandas, the C engine is used as the parser engine by default, and when the file name contains Chinese, the C engine will cause errors in some cases. Therefore, specifying the engine as Python when calling the read_csv () method can solve the problem.
da4 = pd.read_csv ('F: \ Data source \ Project list.csv', engine = 'python')
There is another solution for the second case, which is to use the open function to open the file, and then access the inside Data:
da3 = pd.read_csv (open ('F: \ 4.0 Residential Project Monitoring \ 2.0 Data Source \ 02. Nanjing New Residential Project List.csv'))

Guess you like

Origin www.cnblogs.com/johnyang/p/12751075.html