Unable to import csv file in jupyter note book

Hi,
It has been 3 days I have tried to import csv file and still not completed successfully.
I have watched YouTube videos, google, ChatGPT, bard all the things I have tried
please help me plzzzzzzzzzzzzzzzzzzzzzzzzzzzz.


FileNotFoundError Traceback (most recent call last)
Cell In[9], line 1
----> 1 df = pd.read_csv(“Desktop/IrfanPython/IrfanPython/wrf.csv”)

File ~\anaconda3\lib\site-packages\pandas\util_decorators.py:211, in deprecate_kwarg.._deprecate_kwarg..wrapper(*args, **kwargs)
209 else:
210 kwargs[new_arg_name] = new_arg_value
→ 211 return func(*args, **kwargs)

File ~\anaconda3\lib\site-packages\pandas\util_decorators.py:331, in deprecate_nonkeyword_arguments..decorate..wrapper(*args, **kwargs)
325 if len(args) > num_allow_args:
326 warnings.warn(
327 msg.format(arguments=_format_argument_list(allow_args)),
328 FutureWarning,
329 stacklevel=find_stack_level(),
330 )
→ 331 return func(*args, **kwargs)

File ~\anaconda3\lib\site-packages\pandas\io\parsers\readers.py:950, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, error_bad_lines, warn_bad_lines, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)
935 kwds_defaults = _refine_defaults_read(
936 dialect,
937 delimiter,
(…)
946 defaults={“delimiter”: “,”},
947 )
948 kwds.update(kwds_defaults)
→ 950 return _read(filepath_or_buffer, kwds)

File ~\anaconda3\lib\site-packages\pandas\io\parsers\readers.py:605, in _read(filepath_or_buffer, kwds)
602 _validate_names(kwds.get(“names”, None))
604 # Create the parser.
→ 605 parser = TextFileReader(filepath_or_buffer, **kwds)
607 if chunksize or iterator:
608 return parser

File ~\anaconda3\lib\site-packages\pandas\io\parsers\readers.py:1442, in TextFileReader.init(self, f, engine, **kwds)
1439 self.options[“has_index_names”] = kwds[“has_index_names”]
1441 self.handles: IOHandles | None = None
→ 1442 self._engine = self._make_engine(f, self.engine)

File ~\anaconda3\lib\site-packages\pandas\io\parsers\readers.py:1735, in TextFileReader._make_engine(self, f, engine)
1733 if “b” not in mode:
1734 mode += “b”
→ 1735 self.handles = get_handle(
1736 f,
1737 mode,
1738 encoding=self.options.get(“encoding”, None),
1739 compression=self.options.get(“compression”, None),
1740 memory_map=self.options.get(“memory_map”, False),
1741 is_text=is_text,
1742 errors=self.options.get(“encoding_errors”, “strict”),
1743 storage_options=self.options.get(“storage_options”, None),
1744 )
1745 assert self.handles is not None
1746 f = self.handles.handle

File ~\anaconda3\lib\site-packages\pandas\io\common.py:856, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
851 elif isinstance(handle, str):
852 # Check whether the filename is to be opened in binary mode.
853 # Binary mode does not support ‘encoding’ and ‘newline’.
854 if ioargs.encoding and “b” not in ioargs.mode:
855 # Encoding
→ 856 handle = open(
857 handle,
858 ioargs.mode,
859 encoding=ioargs.encoding,
860 errors=errors,
861 newline=“”,
862 )
863 else:
864 # Binary mode
865 handle = open(handle, ioargs.mode)

FileNotFoundError: [Errno 2] No such file or directory: ‘Desktop/IrfanPython/IrfanPython/wrf.csv’

Have you tried using the documentation for Pandas to make a toy dataframe and save that as .csv file like df.to_csv('my_csv.csv.') (purposefully no complicated path), and then reopened it?
Can then you use your system’s graphical user interface to move the file you are trying to work with to the same place and see if you can open it just using the file name?

It looks like a typical path problem. From inside Jupyter can you see that file and navigate to it properly using pwd and ls and %cd? (Note you have to use the magic version of cd to change the directory and have it take effect beyond that single line.) Explore using those to navigate your system’s hierarchy from inside Jupyter and see if you can get there. (That advice is in expanded form here if that is unclear.)

Are you using OneDrive? That puts files in places that aren’t always clear to the user.

it’s not working.
df.write_csv(‘Desktop/IrfanPython/IrfanPython/wrf.csv’)

could you please connect with me for 5 min
whenever you will be free
8809968819i@gmail.com

That isn’t what I suggested you do. Don’t put anything in front of the file name and try to save it and then work from there. (Plus I had the syntax wrong. I had got distracted and hit send before I confirmed what it was. I edited now; it is df.to_csv('my_csv.csv') . And make sure you have a dataframe defined first. The Pandas documentation offers lots of examples.) The point is to keep it super simple and see what works. You already knew from your previous post that the path you had was a problem. So by still complicating it, you wouldn’t be learning much.

1 Like

sir I am using MS Office 2007 version,
do you think , it may be the reason of not importing csv file in jupyter notebook???

I’m not understanding why MS Office 2007 version being involved would make a difference. If you are really making a pure text based .csv then it should work. There are ways to save those from in Excel but they are not the default ways. You can check though with a standard coding text editor like VSCode or SublimeText if it is in face a pure text file that is comma-separated values? Also you can obtain several examples of comma separated value files on GitHub and if those work and yours doesn’t, then likely you are on the right track about considering how you are making your CSV file.

you can try this
df_2 = pd.read_csv(r’file path’)