pandas库打不开文件,源代码如下
"""
created by mattie
date:0328
用pd打开csv文件
"""
import pandas as pd
def getContent(path):
df = pd.read_csv(open(path), index_col=0)
print(len(df))
print(df.head(2))
return df
df=getContent("D:\mechine learning\transfer-time-location.csv")
df[:3]
"""
报错
OSError: [Errno 22] Invalid argument: 'D:\\mechine learning\transfer-time-location.csv'
解决办法:
以上代码将转义字符’\’修改为’/’,即可运行通过
参考链接