Read csv file through PyCharm - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Read csv file through PyCharm (/thread-34442.html) |
Read csv file through PyCharm - kimx0961 - Jul-31-2021 Dear Madam/Sir, I am beginner to learn python programming through Pycharm. I tried to import csv file thorough Pycharm and current working directory is ‘C:\Users\hakjo\PycharmProjects\jm1’ and python file name is ‘main.py’. When I run the following program, I repeatedly have error messages. I read many postings related to relative vs. absolute path and I don’t see any problem to set the absolute path where ‘sentiment-test.crv’ file is stored. It will be highly appreciated if you can help me to fix this error. import pandas as pd df=pd.read_csv(r’C:\Users\hakjo\PycharmProjects\jm1\sentiment-test.crv’) C:\Users\hakjo\PycharmProjects\jm1\venv\Scripts\python.exe C:/Users/hakjo/PycharmProjects/jm1/main.py Traceback (most recent call last): ** File “C:\Users\hakjo\PycharmProjects\jm1\main.py”, line 6, in ** ** df=pd.read_csv(r’C:\Users\hakjo\PycharmProjects\jm1\sentiment-test.crv’)** ** File “C:\Users\hakjo\PycharmProjects\jm1\venv\lib\site-packages\pandas\util_decorators.py”, line 311, in wrapper** ** return func(args, kwargs) ** File “C:\Users\hakjo\PycharmProjects\jm1\venv\lib\site-packages\pandas\io\parsers\readers.py”, line 586, in read_csv* ** return _read(filepath_or_buffer, kwds)** ** File “C:\Users\hakjo\PycharmProjects\jm1\venv\lib\site-packages\pandas\io\parsers\readers.py”, line 482, in _read** ** parser = TextFileReader(filepath_or_buffer, kwds) ** File “C:\Users\hakjo\PycharmProjects\jm1\venv\lib\site-packages\pandas\io\parsers\readers.py”, line 811, in init** ** self._engine = self._make_engine(self.engine)** ** File “C:\Users\hakjo\PycharmProjects\jm1\venv\lib\site-packages\pandas\io\parsers\readers.py”, line 1040, in _make_engine** ** return mapping[engine](self.f, self.options) # type: ignore[call-arg] ** File “C:\Users\hakjo\PycharmProjects\jm1\venv\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py”, line 51, in init** ** self._open_handles(src, kwds)** ** File “C:\Users\hakjo\PycharmProjects\jm1\venv\lib\site-packages\pandas\io\parsers\base_parser.py”, line 222, in _open_handles** ** self.handles = get_handle(** ** File “C:\Users\hakjo\PycharmProjects\jm1\venv\lib\site-packages\pandas\io\common.py”, line 701, in get_handle** ** handle = open(** FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\hakjo\PycharmProjects\jm1\sentiment-test.crv’ Process finished with exit code 1 Thank you so much Joon RE: Read csv file through PyCharm - ibreeden - Aug-01-2021 Hi Joon, Please read BBCode to learn how to post code and output. The message seems quite clear. Does the file "C:\Users\hakjo\PycharmProjects\jm1\sentiment-test.crv" exist and is it readable? Can you open it with notepad.exe? Should the name not be "C:\Users\hakjo\PycharmProjects\jm1\sentiment-test.csv"?
RE: Read csv file through PyCharm - Axel_Erfurt - Aug-01-2021 You can test the file exists, import os import pandas as pd myfile = r"C:\Users\hakjo\PycharmProjects\jm1\sentiment-test.crv" if os.path.isfile(myfile): df=pd.read_csv(myfile) print(df) else: print(f"file {myfile} does not exist")maybe you can also use myfile = "C:/Users/hakjo/PycharmProjects/m1/sentiment-test.crv" RE: Read csv file through PyCharm - perfringo - Aug-01-2021 Cross-post on SO: https://stackoverflow.com/questions/68606079/read-csv-files-through-pycharm |