Python Forum
importing a CSV file into Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
importing a CSV file into Python
#1
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!
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  New2Python: Help with Importing/Mapping Image Src to Image Code in File CluelessITguy 0 698 Nov-17-2022, 04:46 PM
Last Post: CluelessITguy
  python standard way of importing library mg24 1 872 Nov-15-2022, 01:41 AM
Last Post: deanhystad
  Problem with importing Python file in Visual Studio Code DXav 7 4,911 Jun-15-2022, 12:54 PM
Last Post: snippsat
  importing functions from a separate python file in a separate directory Scordomaniac 3 1,330 May-17-2022, 07:49 AM
Last Post: Pedroski55
  Importing a function from another file runs the old lines also dedesssse 6 2,479 Jul-06-2021, 07:04 PM
Last Post: deanhystad
  Importing text file into excel spreadsheet with formatting david_dsmn 1 3,550 Apr-05-2021, 10:21 PM
Last Post: david_dsmn
  importing a list of numbers into python script barrypyth 8 4,433 Aug-22-2020, 09:10 PM
Last Post: barrypyth
  Importing python data to Textfile or CSV yanDvator 0 1,720 Aug-02-2020, 06:58 AM
Last Post: yanDvator
  Importing data from a text file into an SQLite database with Python macieju1974 7 4,013 Jun-29-2020, 08:51 PM
Last Post: buran
  importing CSV file into a OOP Class table using Python faruk61 1 2,907 Apr-15-2020, 12:00 PM
Last Post: faruk61

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020