When I tried to read a csv into a dataframe in Pandas it can't find my file what are some possible solutions?
Here is the error:
*FileNotFoundError Traceback (most recent call last)
<ipython-input-2-0c537d0c5b39> in <module>
----> 1 data = pd.read_csv('1.01. Simple linear regression.csv')
C:\ProgramData\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)
Make sure you are in the correct directory
Pandas.read_csv, Python will always look in your “current working directory“
data = pd.read_csv('1.01. Simple linear regression.csv')
data.head()
You can always a give a full path
Pandas.read_csv, Python can also look in a specified folder “current working directory“
I have to do by directory path most of the time myself and set my encoding and add a r before also.
data = pd.read_csv(r'C:\Users\path\to\your\file\mess.csv', encoding='utf8')
data.head()
you can also rename the file name to keep it simple
1.01. Simple linear regression.csv
into
1_01_Simple_linear_regression.csv
data = pd.read_csv('C:\Users\path\to\your\file\1_01_Simple_linear_regression.csv')
data.head()
Sometimes you also need to double \ in the path
data = pd.read_csv("C:\\Users\\path\\1_01_Simple_linear_regression.csv")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With