Python Forum

Full Version: importing a CSV file into Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good Morning All,
So I am a complete newbie here and took a class last semester, which was partially programming in Python, but was completely useless as it didn't require any programming. All the programming was done already and just required entering the variable names or copying and pasting a previsions section's code and updating it with new variable names so needless to say I go very little out of it.

So now I am attempting to use Python to model something at work and can't import the CSV file with the data I need. I've downloaded Python 3.8.5 and I'm using Sublimetext. I'm trying to copy the script that was used in class to do some of the work, but I am getting an error message when building. I'm trying to use Pandas to import the CSV. This is the code that I used to import and the message I receive when I build. The CSV file is located on a work server and due to the nature of the work done there I had to remove the file path from the code.
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import scipy as sp

chem_film_data = pd.read_csv (r'S:\\path\path\path\path\path\path\path\chem_film_data_file.csv')
I built after this to see if it would import the data before attempting any additional script and received this message:

File "S:\\path\path\path\path\path\path\path\chem_film_data_file.py" line 7, in <module>


Traceback (most recent call last):

File "S:\\path\path\path\path\path\path\path\chem_film_data_file.py", line 7, in <module>

chem_film_data = pd.read_csv (r'S:\\path\path\path\path\path\path\path\chem_film_data_file.csv.csv')

File "C:\Users\JA21877\AppData\Roaming\Python\Python38\site-packages\pandas\io\parsers.py", line 686, in read_csv

return _read(filepath_or_buffer, kwds)

File "C:\Users\JA21877\AppData\Roaming\Python\Python38\site-packages\pandas\io\parsers.py", line 452, in _read

parser = TextFileReader(fp_or_buf, **kwds)

File "C:\Users\JA21877\AppData\Roaming\Python\Python38\site-packages\pandas\io\parsers.py", line 936, in __init__

self._make_engine(self.engine)

File "C:\Users\JA21877\AppData\Roaming\Python\Python38\site-packages\pandas\io\parsers.py", line 1168, in _make_engine

self._engine = CParserWrapper(self.f, **self.options)

File "C:\Users\JA21877\AppData\Roaming\Python\Python38\site-packages\pandas\io\parsers.py", line 1998, in __init__

self._reader = parsers.TextReader(src, **kwds)

File "pandas\_libs\parsers.pyx", line 361, in pandas._libs.parsers.TextReader.__cinit__

File "pandas\_libs\parsers.pyx", line 653, in pandas._libs.parsers.TextReader._setup_parser_source

FileNotFoundError: [Errno 2] No such file or directory: 'S:/\\path\path\path\path\path\path\path\chem_film_data_file.csv'

[Finished in 2.6s]

Any help would be great and much appreciated!
read_csv is able to load data from the remote source over HTTP-protocol, e.g. something like this:

chem_film_data = pd.read_csv (r'http://your-server.com/static-files/chem_film_data_file.csv')
Probably, you need to specify a separator parameter, e.g. sep=";" in read_csv.