Pandas中OSError Traceback (most recent call last)的一中错误可能

@[TOC](Pandas中OSError Traceback (most recent call last)的一中错误可能)

错误出现

在做《Python数据科学手册》对应的练习时,在 2.4.3节 示例:美国总统的身高是多少,用pandas导入数据文件时输入了正确的路径名

import pandas as pd

data = pd.read_csv('D:\1Haoran\Data reseach\Python_Data_Science_Handbook-master\notebooks\data\president_heights.csv')

却出现了如下报错
Pandas中OSError Traceback (most recent call last)的一中错误可能

OSError Traceback (most recent call last)
in ()
----> 1 data = pd.read_csv(‘D:\1Haoran\Data reseach\Python_Data_Science_Handbook-master\notebooks\data\president_heights.csv’)

C:\Users\llb9531\Anaconda3\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision)。 并在最后提示文件不存在:OSError: File b’D:\x01Haoran\Data reseach\Python_Data_Science_Handbook-master\notebooks\data\president_heights.csv’ does not exist

错误解决

如果你也没有接触过pandas可能也会范这种小错误,pandas在读取文件时
语法应改为

data = pd.read_csv(r'path')

在加了r之后文件被成功读取,不再提示我文件不存在。

data = pd.read_csv(r'D:\1Haoran\Data reseach\Python_Data_Science_Handbook-master\notebooks\data\president_heights.csv')

所查找的帖子

上一篇:结合 RunLoop 和 Instrument 定位卡顿


下一篇:记一次项目启动卡死不动,控制台无错误信息