导入CSV文件错误

时间:2018-08-09 18:13:22

标签: python-3.x csv

在Python中导入CSV文件时,应如何为它编写完整路径?例如:"C:\Users\user\Downloads\insurance.csv"("C:\Users\user\Downloads\insurance.csv")?目前,它给我一个错误:

  

该文件不存在

1 个答案:

答案 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())