如何将.csv文件保存到具有新文件名的目录

时间:2019-09-04 21:40:11

标签: python pandas directory jupyter-notebook save

我在木星实验室里用笔记本工作。我需要使用pandas / python代码以新名称将.csv文件保存到计算机的特定目录下。

问题如下: 将数据保存在“工作”目录中,并将其命名为“数据问题1”

我尝试了很多代码,但这似乎应该可以工作。

import os.path

save_path = '/Users/ccheddar/Class700/Homework/Data/Working'

name_of_file = raw_input("Cityline_Calls_for_Service.csv")

completeName = os.path.join(save_path, name_of_file) 

file1 = open(completeName, "w")

toFile = raw_input("syr_service.csv")

file1.write(toFile)

file1.close()

我不断收到错误消息:

NameError                                 Traceback (most recent call last)
<ipython-input-40-f34c54969f7c> in <module>
      3 save_path = '/Users/ccheddar/Class700/Homework/Data/Working'
      4 
----> 5 name_of_file = raw_input("Cityline_Calls_for_Service.csv")
      6 
      7 completeName = os.path.join(save_path, name_of_file)

NameError: name 'raw_input' is not defined

1 个答案:

答案 0 :(得分:0)

只需删除raw_input

import os.path

save_path = '/Users/ccheddar/Class700/Homework/Data/Working'

name_of_file = "Cityline_Calls_for_Service.csv"

completeName = os.path.join(save_path, name_of_file) 

file1 = open(completeName, "w")

toFile = "syr_service.csv"

file1.write(toFile)

file1.close()