sweetgirl16
sweetgirl16

Reputation: 29

Add path in Python to a Notebook

What am I doing wrong here?

I cannot add a path to my Jupyter Notebook. I am stuck. Any of my attempts did not work at all.

home_dir="\C:\Users\User\Desktop\" data_dir=home_dir + "\C:\Users\User\Desktop\A Student's Guide to Python for Physical Modeling by KInder and Nelson\code" data_set=np.loadtxt(data_dir + "HIVseries.csv", delimiter=',')

Upvotes: 1

Views: 638

Answers (2)

frederick99
frederick99

Reputation: 1053

Change the second line of your code as:

home_dir = "\C:\Users\User\Desktop\"
data_dir = home_dir + "A Student's Guide to Python for Physical Modeling by KInder and Nelson\code"
data_set = np.loadtxt(data_dir + "HIVseries.csv", delimiter=',')

Your code adds the home directory to the data directory. You don't to include the home again. Just providing the relative path would work.

What you were doing would make data_dir equal to \C:\Users\User\Desktop\\C:\Users\User\Desktop\A Student's Guide to Python for Physical Modeling by KInder and Nelson\code which is not a valid path.

Upvotes: 0

Karl Doenitz
Karl Doenitz

Reputation: 2230

It's easy question, modify \C:\Users\User\Desktop\A Student's Guide to Python for Physical Modeling by KInder and Nelson\code to C:\\Users\\User\\Desktop\\A Student's Guide to Python for Physical Modeling by KInder and Nelson\\code.

Upvotes: 1

Related Questions