FileNotFoundError when running: `df = pd.read_csv('Data.csv')`

I am doing the “Chains in LangChain” class, and I am not able to download the sample data using the syntax described in the course. Any advice about how I can get past this? (I copied the code from the course notebook, so am sure I don’t have any typos). This does work in the sample notebook supplied with the course.

I feel like I need to download that file onto my computer, but I am not clear where to find it, or if this is the step I need to do (this is not explained in the course materials).

My complete code:

import pandas as pd
df = pd.read_csv('Data.csv')

results in the following error:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[19], line 2
      1 import pandas as pd
----> 2 df = pd.read_csv('Data.csv')

File ~\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\readers.py:912, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, 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, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend)
    899 kwds_defaults = _refine_defaults_read(
    900     dialect,
    901     delimiter,
   (...)
    908     dtype_backend=dtype_backend,
    909 )
    910 kwds.update(kwds_defaults)
--> 912 return _read(filepath_or_buffer, kwds)

File ~\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\readers.py:577, in _read(filepath_or_buffer, kwds)
    574 _validate_names(kwds.get("names", None))
    576 # Create the parser.
--> 577 parser = TextFileReader(filepath_or_buffer, **kwds)
    579 if chunksize or iterator:
    580     return parser

File ~\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\readers.py:1407, in TextFileReader.__init__(self, f, engine, **kwds)
   1404     self.options["has_index_names"] = kwds["has_index_names"]
   1406 self.handles: IOHandles | None = None
-> 1407 self._engine = self._make_engine(f, self.engine)

File ~\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\readers.py:1661, in TextFileReader._make_engine(self, f, engine)
   1659     if "b" not in mode:
   1660         mode += "b"
-> 1661 self.handles = get_handle(
   1662     f,
   1663     mode,
   1664     encoding=self.options.get("encoding", None),
   1665     compression=self.options.get("compression", None),
   1666     memory_map=self.options.get("memory_map", False),
   1667     is_text=is_text,
   1668     errors=self.options.get("encoding_errors", "strict"),
   1669     storage_options=self.options.get("storage_options", None),
   1670 )
   1671 assert self.handles is not None
   1672 f = self.handles.handle

File ~\AppData\Roaming\Python\Python311\site-packages\pandas\io\common.py:859, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
    854 elif isinstance(handle, str):
    855     # Check whether the filename is to be opened in binary mode.
    856     # Binary mode does not support 'encoding' and 'newline'.
    857     if ioargs.encoding and "b" not in ioargs.mode:
    858         # Encoding
--> 859         handle = open(
    860             handle,
    861             ioargs.mode,
    862             encoding=ioargs.encoding,
    863             errors=errors,
    864             newline="",
    865         )
    866     else:
    867         # Binary mode
    868         handle = open(handle, ioargs.mode)

FileNotFoundError: [Errno 2] No such file or directory: 'Data.csv'

Hi @boogermike

I tried it and had no problems loading the dataset.

Did you run all the cells from top to bottom?

Hi @boogermike,

Based on this, I’m assuming you are trying to run this locally. Yes, you need all the relevant files and data kn order to run this locally.

Go to the short course’s lecture page and wait for the notebook to load. Once loaded, click on File-->Open... on the top left. It should open things in a new tab, where you’ll see the workspaces and all the files which you can download.

Cheers,
Mubsi

2 Likes

Thanks for your response @Mubsi - you are totally correct, and starting the notebook in the way you suggested DID solve my issue.

I have been creating local notebooks, and that didn’t work for this lab.

Really appreciate your help!

After starting the notebook in the suggested way, I could find the Data.csv file, which I downloaded to the same folder where my local notebook is, and the file was able to be located (and I could complete the lab).

1 Like