在Python中导入CSV文件时,应如何为它编写完整路径?例如:"C:\Users\user\Downloads\insurance.csv"
或("C:\Users\user\Downloads\insurance.csv")
?目前,它给我一个错误:
该文件不存在
答案 0 :(得分:0)
不,不,不,就像这样。
data_folder = "source_data\\text_files\\"
file_to_open = data_folder + "raw_data.txt"
f = open(file_to_open)
print(f.read())
或者...这个...
from pathlib import Path
data_folder = Path("source_data/text_files/")
file_to_open = data_folder / "raw_data.txt"
f = open(file_to_open)
print(f.read())