一个特定的独角兽

2024-03-28 14:08:24 发布

您现在位置:Python中文网/ 问答频道 /正文

这可能不是Pandas特有的,但是我得到了这个错误,对于在C:驱动器中创建的一个小测试文件。尝试搜索“unicode错误”,但这个似乎不同。怎么了?在

import pandas as pd
import matplotlib.pyplot as plt
df  = pd.read_csv("C:\Users\arny\data.csv")
df.plot()  # plots all columns against index
df.plot(kind='scatter',x='x',y='y') # scatter plot
df.plot(kind='density')  # estimate density function
# df.plot(kind='hist')  # histogram

文件“”,第3行 SyntaxError:(unicode错误)“UnicodeScape”编解码器无法解码位置2-3中的字节:截断\uxxxxxxxxx转义


Tags: 文件csvimportpandasdfplotas错误
1条回答
网友
1楼 · 发布于 2024-03-28 14:08:24

问题出在绳子上

"C:\Users\arny\data.csv"

在这里,\U开始一个8字符的Unicode转义符,例如'\U00014321`。在代码中,转义符后跟字符“s”,这是无效的。在

您要么需要复制所有反斜杠('\'),要么在字符串前面加上r(以生成原始字符串)。在

相关问题 更多 >