如何在Python中设置当前工作目录?
当前回答
尝试os.chdir
进口操作系统 os.chdir(路径) 将当前工作目录更改为path。可用性:Unix, Windows。
其他回答
它也适用于Mac
import os
path="/Users/HOME/Desktop/Addl Work/TimeSeries-Done"
os.chdir(path)
检查工作目录
os.getcwd()
人们使用熊猫包装
import os
import pandas as pd
tar = os.chdir('<dir path only>') # do not mention file name here
print os.getcwd()# to print the path name in CLI
下面的语法将用于在python CLI中导入文件
dataset(*just a variable) = pd.read_csv('new.csv')
import os
print os.getcwd() # Prints the current working directory
设置工作目录。
os.chdir('c:\\Users\\uname\\desktop\\python') # Provide the new path here
也许这就是你想要的:
import os
os.chdir(default_path)
尝试os.chdir
进口操作系统 os.chdir(路径) 将当前工作目录更改为path。可用性:Unix, Windows。