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.

5
  • what is the issue your facing here? Commented Jun 19, 2020 at 16:32
  • 2
    is the file in the same directory you're running the script from? Commented Jun 19, 2020 at 16:34
  • make sure inflammation-01.csv is in same directory as your py file else you have to specify the full path Commented Jun 19, 2020 at 16:35
  • Does this answer your question? Reading data from a CSV file in Python Commented Jun 19, 2020 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. Commented Jun 22, 2020 at 10:40

2 Answers 2

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

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

Comments

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.

1 Comment

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)

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.