我正在尝试在python(jupyter笔记本)中读取csv文件,但出现错误。下面是代码:
import sys
import pandas as pd
import scipy
import numpy as np
import seaborn as sns
import matplotlib
import sklearn
import matplotlib.pyplot as plt
pwd
data = pd.read_csv("C:\Users\DELL\Desktop\creditcard.csv")
SyntaxError:(unicode错误)“ unicodeescape”编解码器无法解码位置2-3中的字节:截断的\ UXXXXXXXX转义
https://i.stack.imgur.com/l6kl7.png
编辑:我已经尝试了以下所有方法,但仍然遇到相同的错误。
data = pd.read_csv("C:\Users\DELL\Desktop\creditcard.csv")
data = pd.read_csv("C:\\Users\\DELL\\Desktop\\creditcard.csv")
data = pd.read_csv(r"C:\Users\DELL\Desktop\creditcard.csv")
data = pd.read_csv(r"C:\\Users\\DELL\\Desktop\\creditcard.csv")
data = pd.read_csv("C:/Users/DELL/Desktop/creditcard.csv")
data = pd.read_csv("C://Users//DELL//Desktop//creditcard.csv")
data = pd.read_csv(r"C:/Users/DELL/Desktop/creditcard.csv")
data = pd.read_csv(r"C://Users//DELL//Desktop//creditcard.csv")
此外,我用单引号(')尝试了所有方法,但没有用。这是文件详细信息的图片:https://i.stack.imgur.com/NmeoB.png
答案 0 :(得分:2)
您可以尝试以下任何一种解决方案:-
b
答案 1 :(得分:0)
您可以使用实际路径将r放在字符串的前面,这表示原始字符串。例如:
data = pd.read_csv(r"C:\Users\DELL\Desktop\creditcard.csv")
答案 2 :(得分:0)
尝试一下。将解决此问题。
PeriodicWorkRequestBuilder