天道酬勤,学无止境

Unable to read csv file by Anaconda IDE

问题

我的 Anaconda IDE 无法使用panda.read_csv()函数读取 csv 文件。

文件名是棒球,保存在位置C:\Users\Firdaus\Desktop

我写了以下代码:

# Import pandas as pd
import pandas as pd
# Import the cars.csv data as Base
Base = pd.read_csv('C:\Users\Firdaus\Desktop\baseball.csv')
# Print out Base
print(Base)

错误是:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

回答1

在常规 python 字符串中,\U 字符组合表示扩展的 Unicode 代码点转义。 您可以使用以下方法之一:

r'C:\Users\Firdaus\Desktop\baseball.csv' #r stands for raw strings
'C:\\Users\\Firdaus\\Desktop\\baseball.csv' #using double slashes
'C:/Users/Firdaus/Desktop/baseball.csv' #using forward slashes

希望这可以帮助。

标签

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • Unable to read csv file by Anaconda IDE
    My Anaconda IDE is unable to read csv file using panda.read_csv() function. File name is baseball which is kept at location C:\Users\Firdaus\Desktop I have written following code: # Import pandas as pd import pandas as pd # Import the cars.csv data as Base Base = pd.read_csv('C:\Users\Firdaus\Desktop\baseball.csv') # Print out Base print(Base) Error is: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
  • 无法在gdal中加载“ gcs.csv”文件(unable to load “gcs.csv” file in gdal)
    问题 这个问题可能会重复,但是我没有得到答案。 我已经在python ide中编写了流畅的代码。 out_srs = osr.SpatialReference() **self.out_srs.ImportFromEPSG(4326)** 它运行正常,但是当我从应用程序运行时会导致如下错误 注意-两星括起来的行中的错误----- "Unable to load EPSG support gcs.csv file check setting GDAL_DATA environment variable which point to gdal library contains EPSG.csv file" 我已经做到了,但仍然收到此错误。 但是此代码单独运行,但不能在应用程序中运行。 此代码来自gdal的gdal2tile模块。 我正在使用python 2.7.6和gdal 1.10.0,我无法找出问题所在和所在位置。 请提出解决方法。 回答1 GDAL需要一个名为GDAL_DATA的环境变量,该变量指向包含各种数据文件(包括gcs.csv 。 点击此处了解详情。 要检查是否设置了GDAL_DATA并包含gcs.csv ,以及是否可读,请使用以下代码片段检查应用程序。 这应该靠近引发错误的代码。 import os import stat gdal_data = os.environ[
  • 无法使用 seaborn.countplot(Unable to use seaborn.countplot)
    问题 我正在尝试使用最新版本的 Pycharm 作为 Python IDE 绘制一些图形。 作为解释器,我将 Anaconda 与 Python 3.4.3-0 一起使用。 我已经使用conda install新闻版的 pandas (0.17.0), seaborn (0.6.0), numpy (1.10.1), matplotlib (1.4.3), ipython (4.0.1) 在 nesarc_pds.csv 我有这个: IDNUM,S1Q2I 39191,1 39787,1 40082,1 40189,1 40226,1 40637,1 41306,1 41627,1 41710,1 42113,1 42120,1 42720,1 42909,1 43092,1 7,2 15,2 25,2 40,2 46,2 49,2 57,2 63,2 68,2 100,2 104,2 116,2 125,2 136,2 137,2 145,2 168,2 3787,9 6554,9 7616,9 11686,9 12431,9 14889,9 17694,9 19440,9 20141,9 21540,9 22476,9 24207,9 25762,9 29045,9 29731,9 所以,话虽如此,这是我的代码: import pandas as pd import numpy
  • Unable to use seaborn.countplot
    I'm trying to plot some graphs using the latest version of Pycharm as a Python IDE. As an interpreter, I'm using Anaconda with Python 3.4.3-0. I have installed using conda install the news version of pandas (0.17.0), seaborn (0.6.0), numpy (1.10.1), matplotlib (1.4.3), ipython (4.0.1) Inside the nesarc_pds.csv I have this: IDNUM,S1Q2I 39191,1 39787,1 40082,1 40189,1 40226,1 40637,1 41306,1 41627,1 41710,1 42113,1 42120,1 42720,1 42909,1 43092,1 7,2 15,2 25,2 40,2 46,2 49,2 57,2 63,2 68,2 100,2 104,2 116,2 125,2 136,2 137,2 145,2 168,2 3787,9 6554,9 7616,9 11686,9 12431,9 14889,9 17694,9 19440
  • 带有嵌入引号的文件名的“CSV 文件不存在”(“CSV file does not exist” for a filename with embedded quotes)
    问题 我目前正在学习 Pandas 进行数据分析,并且在 Atom 编辑器中读取 csv 文件时遇到了一些问题。 当我运行以下代码时: import pandas as pd df = pd.read_csv("FBI-CRIME11.csv") print(df.head()) 我收到一条错误消息,以 OSError:文件 b'FBI-CRIME11.csv' 不存在 这是文件的目录:/Users/alekseinabatov/Documents/Python/"FBI-CRIME11.csv"。 当我尝试以这种方式运行它时: df = pd.read_csv(Users/alekseinabatov/Documents/Python/"FBI-CRIME11.csv") 我收到另一个错误: NameError:未定义名称“用户” 我也将此目录放入编辑器设置中的“Project Home”字段中,但我不太确定它是否有任何区别。 我敢打赌,有一种简单的方法可以让它发挥作用。 我将衷心感谢您的帮助! 回答1 你有没有尝试过? df = pd.read_csv("Users/alekseinabatov/Documents/Python/FBI-CRIME11.csv") 或者可能 df = pd.read_csv('Users/alekseinabatov/Documents
  • Unable to submit Spark job from Windows IDE to Linux cluster
    I just read about findspark and found it quite interesting, as so far I have only used spark-submit which isn't be suited for interactive development on an IDE. I tried executing this file on Windows 10, Anaconda 4.4.0, Python 3.6.1, IPython 5.3.0, Spyder 3.1.4, Spark 2.1.1: def inc(i): return i + 1 import findspark findspark.init() import pyspark sc = pyspark.SparkContext(master='local', appName='test1') print(repr(sc.parallelize(tuple(range(10))).map(inc).collect())) Spyder generates the command runfile('C:/tests/temp1.py', wdir='C:/tests') and it prints out [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  • Pandas Dataframe - RemoteDataError - Python
    问题 我正在尝试从雅虎财经中提取数据。 这是我得到的错误: File "banana.py", line 35, in <module> data = web.DataReader(ticker, "yahoo", datetime(2011,1,1), datetime(2015,12,31)) File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\data.py", line 94, in DataReader session=session).read() File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\yahoo\daily.py", line 77, in read df = super(YahooDailyReader, self).read() File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\base.py", line 173, in read df = self._read_one_data(self.url, params=self._get_params(self.symbols)) File "C:\Users\ll
  • Pandas Dataframe - RemoteDataError - Python
    I'm trying to pull data from yahoo finance. Here is the error I'm getting: File "banana.py", line 35, in <module> data = web.DataReader(ticker, "yahoo", datetime(2011,1,1), datetime(2015,12,31)) File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\data.py", line 94, in DataReader session=session).read() File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\yahoo\daily.py", line 77, in read df = super(YahooDailyReader, self).read() File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\base.py", line 173, in read df = self._read_one_data(self.url, params=self._get
  • Pylint does not work in visual studio code
    问题 我在 Mac 上使用 Visual Studio 代码作为 python IDE,一切正常。 但几周前,我开始使用 Windows。 突然间,我无法在我在 Mac 上开始的项目中使用 pylint。 我有 显式激活 pylintEnabled 选项 (=True) pylint.exe 的完整路径已设置(“c:\Anaconda 3...”) 带有初始钩子的pylintrc文件将项目添加到根目录中的 pythonpath(由 pylint 使用 --generate-rcfile 生成)。 使用相同的参数,在 Linux(Ubuntu 16.10)和 Mac 上一切正常。 并且不能在两台 Windows 机器上工作。 似乎 pylint 只是没有运行。 我哪里做错了? 更新: 我发现 pylint 得到了 UnicodeDecodingError: ##########Linting Output - pylint########## Traceback (most recent call last): File "C:\Program Files\Anaconda3\Scripts\pylint-script.py", line 5, in <module> sys.exit(pylint.run_pylint()) File "C:\Program Files
  • ValueError: array must not contain infs or NaNs during Biclustering
    I'm trying to model biclustering, but it's failing as it says array contains infs and nans, though I scanned array using pd.isnull(DataFile).sum() import pandas as pd import numpy as np from matplotlib import pyplot as plt from sklearn.datasets import samples_generator as sg from sklearn.cluster.bicluster import SpectralCoclustering from sklearn.metrics import consensus_score DataFile=pd.read_csv("DatafilledProp.csv",sep='\t') DataFile.drop(DataFile.columns[[0, 1]], axis=1, inplace=True) plt.matshow(DataFile.as_matrix(), cmap=plt.cm.Blues) plt.title("Original TransMapping") data, row_idx, col
  • 致命的Python错误:Py_Initialize:无法加载文件系统编解码器。 ImportError:没有名为“编码”的模块(Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings')
    问题 我正在尝试制作简单的python程序,该程序正在打开网页列表,以供用户从网站手动下载报告。 我以前没有准备exe文件的经验。.我只是在学习python编码的过程。 所有这些都是在Windows 7 x64上完成的 这是我的python代码: #!C:/Python34/python.exe -u from splinter import * import time import os import csv #---------------------------------- raporty = [] with open('../raporty.csv', newline='') as csvfile: contents = csv.reader(csvfile, delimiter=' ', quotechar='|') for row in contents: r = ', '.join(row) r = r.replace(',','') raporty.append(r) #--not implemented yet zmienne = [] with open('../zmienne.csv', newline='') as csvfile: contents = csv.reader(csvfile, delimiter=' ', quotechar='|')
  • Pylint does not work in visual studio code
    I use Visual Studio code as python IDE on Mac, and everything works fine for me. But a couple of weeks ago I've started to use Windows. And suddenly I'm unable to use pylint in the project I've started on Mac. I have explicitly activated pylintEnabled option (=True) full path to pylint.exe is set ("c:\Anaconda 3...") pylintrc file with initial hook adding project to pythonpath (generated by pylint using --generate-rcfile) in the root directory. With the very same parameters, everything works fine both on Linux (Ubuntu 16.10) and Mac. And does not work on two Windows machines. It seems that the
  • Reading a csv file in batch mode using pyflink from local system
    I was trying to read an established csv file while writing a pyflink job. I was using filesystem connector to get the data but after executing execute_sql() on the ddl and later doing query on the table I was getting an error which explains that it isn't able to fetch the next result. I am unable to resolve this error. I have checked the csv file and it's fully correct and working with pandas but here I don't why it isn't able to fetch the next line. For reference please find the attached code. from pyflink.common.serialization import SimpleStringEncoder from pyflink.common.typeinfo import
  • Unable to Include Jinja2 Template to Pyinstaller Distribution
    问题 我有一个使用 Jinja2 模板的 python 脚本,我正在尝试使用 Pyinstaller 创建一个单文件夹分发。 在 Jinja 中,我通过使用PackageLoader类让程序了解模板的位置。 下面的代码显示它指向我在pycorr Python 包下的templates文件夹。 env = Environment(loader=PackageLoader('pycorr', 'templates')) template = env.get_template('child_template.html') 这是我的文件夹结构: pycorr | | | + templates | | | + base.html | + child.html 当我使用 Pyinstaller 将包编译到单个文件夹中时,我没有看到任何与 Jinja2 相关的警告/错误,并且我能够启动 .exe 文件。 但是,当程序开始寻找 Jinja2 模板时,它会失败并在控制台窗口上显示以下错误消息: Traceback (most recent call last): ... File "C:\Users\ ... \out00-PYZ.pyz\pycorr.WriterToHTML", line 96, in htmlout_table File "C:\Users\ ... \out00-PYZ
  • Rodeo UnicodeDecodeError:“ascii”编解码器无法解码位置 0 中的字节 0xef:序号不在范围内(128)(Rodeo UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128))
    问题 我刚刚开始使用 Python3。 我正在尝试使用 Rodeo IDE 打开一个 csv 文件 fp = open('Proteomics_Data.csv') # open file on read mode lines = fp.read().split("\n") # create a list containing all lines 我收到一个错误,我将其粘贴在下面。 UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128) --------------------------------------------------------------------------- UnicodeDecodeError Traceback (most recent call last) <ipython-input-347-aebf19dd596a> in <module>() ----> 1 lines = fp.read().split("\n") /Users/alessandro/anaconda/lib/python3.6/encodings/ascii.py in decode(self, input, final) 24
  • ValueError: 数组在 Biclustering 期间不能包含 infs 或 NaNs(ValueError: array must not contain infs or NaNs during Biclustering)
    问题 我正在尝试对 biclustering 进行建模,但它失败了,因为它说数组包含infs和nans ,尽管我使用pd.isnull(DataFile).sum()扫描了数组 import pandas as pd import numpy as np from matplotlib import pyplot as plt from sklearn.datasets import samples_generator as sg from sklearn.cluster.bicluster import SpectralCoclustering from sklearn.metrics import consensus_score DataFile=pd.read_csv("DatafilledProp.csv",sep='\t') DataFile.drop(DataFile.columns[[0, 1]], axis=1, inplace=True) plt.matshow(DataFile.as_matrix(), cmap=plt.cm.Blues) plt.title("Original TransMapping") data, row_idx, col_idx = sg._shuffle(DataFile.as_matrix(), random_state=0)
  • Can no Longer open Spyder IDE for Python Programming
    I installed Python 3.4 on my Windows 7 laptop several months ago as part of Anaconda (https://www.continuum.io/downloads). My installation included the Spyder IDE, and I have successfully been using Spyder for Python programming. However, since yesterday, I have been unable to open Spyder. I typically open Spyder via the Start Menu, but now, when I try to click on the Spyder icon in the Start Menu, I get no response. I then tried to go directly to the spyder.exe file in the Scripts folder in the directory where Anaconda is installed. When I clicked on this the first time, the following message
  • 为什么pydot无法在Windows 8中找到GraphViz的可执行文件?(Why is pydot unable to find GraphViz's executables in Windows 8?)
    问题 我在Windows 8中安装了GraphViz 2.32,并将C:\ Program Files(x86)\ Graphviz2.32 \ bin添加到系统PATH变量中。 pydot仍然找不到其可执行文件。 Traceback (most recent call last): File "<pyshell#26>", line 1, in <module> graph.write_png('example1_graph.png') File "build\bdist.win32\egg\pydot.py", line 1809, in <lambda> lambda path, f=frmt, prog=self.prog : self.write(path, format=f, prog=prog)) File "build\bdist.win32\egg\pydot.py", line 1911, in write dot_fd.write(self.create(prog, format)) File "build\bdist.win32\egg\pydot.py", line 1953, in create 'GraphViz\'s executables not found' ) InvocationException: GraphViz's
  • Python 2.7: Unable to import matplotlib.pyplot
    When I tried to import matplotlib.pyplot as plt I was given the following error: runfile('/Users/Zhengnan/Documents/Python/PS 2/230I_PS_2.py', wdir='/Users/Zhengnan/Documents/Python/PS 2') Traceback (most recent call last): File "<ipython-input-2-9001323bba15>", line 1, in <module> runfile('/Users/Zhengnan/Documents/Python/PS 2/230I_PS_2.py', wdir='/Users/Zhengnan/Documents/Python/PS 2') File "/Users/Zhengnan/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 685, in runfile execfile(filename, namespace) File "/Users/Zhengnan/anaconda/lib/python2.7
  • 使用 pandas read_csv 时出现内存错误(Memory error when using pandas read_csv)
    问题 我正在尝试做一些相当简单的事情,将一个大的 csv 文件读入一个 Pandas 数据帧。 data = pandas.read_csv(filepath, header = 0, sep = DELIMITER,skiprows = 2) 代码要么因MemoryError失败,要么永远不会完成。 任务管理器中的内存使用量在 506 Mb 处停止,在 5 分钟没有变化且进程中没有 CPU 活动后,我停止了它。 我正在使用熊猫版本 0.11.0。 我知道文件解析器曾经存在内存问题,但根据http://wesmckinney.com/blog/?p=543应该已经修复了。 我试图读取的文件是 366 Mb,如果我将文件缩减为较短的文件(25 Mb),则上面的代码有效。 还发生了一个弹出窗口,告诉我它无法写入地址 0x1e0baf93 ... 堆栈跟踪: Traceback (most recent call last): File "F:\QA ALM\Python\new WIM data\new WIM data\new_WIM_data.py", line 25, in <module> wimdata = pandas.read_csv(filepath, header = 0, sep = DELIMITER,skiprows = 2 ) File "C:\Program