2

I started with a tutorial that showed how to import Pandas and now I want to read the CSV file. I feel like I have tried everything. I tried all different types of encoding commands, that doesn't seem to do anything - I keep getting the same error - that the CSV file does not exist. I tried including the full path name, and saving the CSV file in different places (currently on my desktop). Nothing. Would someone please explain to me what I could be doing wrong in layman terms, as I have no clue. It feels like it could be something so simple!

# Pandas for managing datasets
import pandas as pd
# Matplotlib for additional customization
from matplotlib import pyplot as plt
%matplotlib inline
# Seaborn for plotting and styling
import seaborn as sns
# Read dataset
df = pd.read_csv('Pokemon.csv', index_col=0)

Traceback

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-9-b0b02dbb5c90> in <module>
      1 # Read dataset
----> 2 df = pd.read_csv('Pokemon.csv', index_col=0)

~\anaconda3\lib\site-packages\pandas\io\parsers.py in parser_f(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, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)

3 Answers 3

2

Generally anytime you get a FileNotFoundError, it's an issue with your program finding the file.

You can be sure you have the right file path by navigating to the file on your computer, as though you were going to open it. Then right-click and select Properties. I can't speak for Linux or Mac, but on Windows you'll find the file path under the "Security" tab in a field called "Object Name". You can copy/paste that file path into your program like this:

pd.read_csv(r'(paste your file path here, and remove parentheses)')

Also, be sure to include the r before your file path string. That will tell Python to escape the backslashes in Windows file paths.

Sign up to request clarification or add additional context in comments.

2 Comments

Andy, this was so clear, and easy to follow. Thank you! But unfortunately, did not work: # Read dataset df = pd.read_csv(r '‪C:\Users\Me\Desktop\Pokemon.csv', index_col=0) # Read dataset df = pd.read_csv(r '‪C:\Users\Me\Desktop\Pokemon.csv', index_col=0) File "<ipython-input-1-5e2a11c7de18>", line 2 df = pd.read_csv(r '‪C:\Users\Me\Desktop\Pokemon.csv', index_col=0) ^ SyntaxError: invalid syntax
@HazelSayer what was the syntax error you were given in the comment above?
1

I recommend checking to see what where you have opened your Jupyter Notebook. Open the Notebook in the same directory that 'Pokemon.csv' is in or put your csv file in the directory that you opened your Jupyter notebook. I know you said that you have put the full path name in, but that shouldn't be necessary.

2 Comments

Thank you for your reply. Saved in the same directory. I then get a unicode error! So frustrating :-(
Can you show what the unicode error says? Coding is frustrating. You just have to take it one step at a time and learn through practice.
1

Check your current working directory:

import os
os.getcwd()

Sample Output:

'C:\\Users\\WORKSTATION\\Downloads'

if the file is in this folder, then you will be able to do:

df = pd.read_csv('Pokemon.csv', index_col=0)

else, get the directory of your file, then do: (Sample directory, say in Documents)

df = pd.read_csv('C:\\Users\\WORKSTATION\\Documents\\Pokemon.csv', index_col=0)

or

df = pd.read_csv(r'C:\Users\WORKSTATION\Documents\Pokemon.csv', index_col=0)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.