简体   繁体   中英

Python for Data Analysis, Chapter 2, first example

I'm following along with the examples in a translated version of Wes McKinney's "Python for Data Analysis" and I was blocked in first example of Chapter 2

I think my problem arose because I saved a data file in a wrong path. is that right?

在此处输入图片说明

I stored a file, usagov_bitly_data2012-03-16-1331923249.txt , in C:\\Users\\HRR and also stored folder, pydata-book-mater , that can be downloaded from http://github.com/pydata-book in C:\\Users\\HRR\\Anaconda2\\Library\\bin .

Depends.

You might change the location you save your File or eddit the path you give to your code in Line 10. Since you're yousing relativ Paths i guess your script runs in C:\\Users\\HRR\\Anaconda2\\Library\\bin, which means you have to go back to C:\\Users\\HRR or use an absolute Path ... or move the File, but hell you don't want to move a file every time you want to open it, like moving word files into msoffice file to open it, so try to change the Path.

And allways try harder ;)

In python open() will open from the current directory down unless given a full path (in linux that starts with / and windows <C>:// ). In your case the command is open the folder ch02 in the directory the script is running from and then open usagov_bitly_data2012-03-16-1331923249.txt in that folder.

Since you are storing the text file in C:\\Users\\HRR\\usagov_bitly_data2012-03-16-1331923249.txt and you did not specify the directory of the script. I recommend the following command instead open(C:\\\\Users\\\\HRR\\\\usagov_bitly_data2012-03-16-1331923249.txt)

Note: the double \\ is to escape the characters and avoid tabs and newlines showing up in the path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM