0

I am trying to open this file called inflammation-01.csv. The full activity can be found here

https://swcarpentry.github.io/python-novice-inflammation/02-numpy/index.html.

It carries on saying that it cannot find the specifed file.

import numpy
fname= ('inflammation-01.csv')
numpy.loadtxt(fname, delimiter=',')

Thank you for any help.

Narendra Prasath
  • 1,501
  • 1
  • 10
  • 20
  • what is the issue your facing here? – Narendra Prasath Jun 19 '20 at 16:32
  • 2
    is the file in the same directory you're running the script from? – Dorian Jun 19 '20 at 16:34
  • make sure `inflammation-01.csv` is in same directory as your py file else you have to specify the full path – Isaac Frank Jun 19 '20 at 16:35
  • Does this answer your question? [Reading data from a CSV file in Python](https://stackoverflow.com/questions/26903304/reading-data-from-a-csv-file-in-python) – Joe Jun 19 '20 at 17:07
  • Well I am running it in a Jupyter Notebook so how do I put that in the same directory. I specified a path but it still said could not find. Thank you for the link I tried the codes from the link bu they did not work. – Fullmetal0310 Jun 22 '20 at 10:40

2 Answers2

0

Make sure to have the CSV file in the same directory as your program running
Or you may use whole directory to the CSV file

Just some suggestion from me:
You may use module pandas to work with csv file

import pandas as pd 
data = pd.read_csv("filename.csv") 
data.head()

More information: https://www.shanelynn.ie/python-pandas-read_csv-load-data-from-csv-files/

More detail about pandas:https://pandas.pydata.org/docs/user_guide/index.html#user-guide

Goodluck with your project :D

Amirul Akmal
  • 401
  • 6
  • 13
0

Is the file in the same folder, than the script you are running? If not try:

fname= (r'C:\<path_to__File>\inflammation-01.csv')

replacing C:\<path_to__File> with the correct path.

The "r" in front of the filename makes it a raw string, which often helps avoiding problems with backslashes in path names.

chris
  • 170
  • 1
  • 9
  • Can you post the error message? Will help to identify the problem. Maybe there are non-numerical column headers? Then this will do the job: `import numpy fname= (r'C:\Temp\inflammation-01.csv') data = numpy.loadtxt(fname, delimiter=';', skiprows=1)` – chris Jun 22 '20 at 12:08