Python Forum
Read csv file through PyCharm
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read csv file through PyCharm
#1
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
Reply
#2
Hi Joon,
Please read BBCode to learn how to post code and output.
Error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\hakjo\PycharmProjects\jm1\sentiment-test.crv’
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"?
Reply
#3
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"
Reply
#4
Cross-post on SO: https://stackoverflow.com/questions/68606079/read-csv-files-through-pycharm
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Recommended way to read/create PDF file? Winfried 3 2,783 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,308 Nov-09-2023, 10:56 AM
Last Post: mg24
  read file txt on my pc to telegram bot api Tupa 0 1,047 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,043 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,160 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 6,006 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Read csv file with inconsistent delimiter gracenz 2 1,140 Mar-27-2023, 08:59 PM
Last Post: deanhystad
  Read text file, modify it then write back Pavel_47 5 1,499 Feb-18-2023, 02:49 PM
Last Post: deanhystad
  Correctly read a malformed CSV file data klllmmm 2 1,813 Jan-25-2023, 04:12 PM
Last Post: klllmmm
  How to read csv file update matplotlib column chart regularly SamLiu 2 1,015 Jan-21-2023, 11:33 PM
Last Post: SamLiu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020