When reading a data file when operating Python, The directory in which the file is stored must be the current directory. In this memo, the directory where the data is already stored is The method of setting as the current directory is described.
To work with directories, you need to import
the os
module.
Enter the following sentence.
import os
Below, first check where the current directory is set, and then set the directory containing the data you want to read to the current directory.
os.getcwd()
The result is below.
>>> os.getcwd()
'C:\\Users\\ozspade\\AppData\\Local\\Continuum\\Anaconda3\\Scripts'
I don't put the analysis data in such a place. I put the data below.
C:\\Users\\ozspade\\Documents\\PythonScripts
Set this to the current directory.
Enter as follows.
os.chdir("C:\\Users\\ozspade\\Documents\\PythonScripts")
This completes the setting, and check the current directory again.
>>> os.getcwd()
'C:\\Users\\ozspade\\Documents\\PythonScripts'
I was able to safely specify the directory where the analysis data is located. I'm happy.
Recommended Posts