pandas.open_csv(“文件名”)显示错误

cnh2zyt3  于 2023-03-05  发布在  其他
关注(0)|答案(1)|浏览(119)
File "c:\Users\haris\backlog.py\filo6.py", line 20, in <module>
    data=pandas.read_csv("coordinata.csv",encoding = "ISO-8859-1",delimiter=',')
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\haris\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\haris\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\haris\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\io\parsers\readers.py", line 950, in read_csv
    return _read(filepath_or_buffer, kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\haris\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\io\parsers\readers.py", line 605, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\haris\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\io\parsers\readers.py", line 1442, in __init__
    self._engine = self._make_engine(f, self.engine)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\haris\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\io\parsers\readers.py", line 1735, in _make_engine
    self.handles = get_handle(
                   ^^^^^^^^^^^
  File "C:\Users\haris\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\io\common.py", line 856, in get_handle
    handle = open(
             ^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'coordinata.csv'

我正在用tkinter制作一个项目。我必须通过将Excel文件转换为CSV来导入它,但是这个CSV文件显示这个错误。

fd3cxomn

fd3cxomn1#

要解决此问题,您可以尝试以下步骤:
1.检查Python脚本的当前工作目录,并确保CSV文件位于同一目录中,您可以使用os模块获取当前工作目录并列出目录中的文件。
1.如果CSV文件位于其他目录中,则需要在www.example.com_csv()函数中提供正确的路径。可以使用绝对路径或相对路径指定文件的位置。 pandas.read _csv() function. You can use an absolute path or a relative path to specify the location of the file.
1.请确保文件名和扩展名拼写正确。文件名区分大小写,因此请确保文件名的大小写正确。
1.如果文件位于名称中包含空格的文件夹中,则需要用引号将路径括起来以防止错误。
下面是如何使用os模块检查当前工作目录并列出文件的示例:

import os

# Get the current working directory
cwd = os.getcwd()
print("Current working directory:", cwd)

# List the files in the directory
files = os.listdir(cwd)
print("Files in the directory:", files)

确保CSV文件列在os. listdir()函数的输出中,如果没有列出,则需要将文件移动到正确的位置或在www.example.com_csv()函数中提供正确的路径。pandas.read_csv() function.

相关问题