话不多说,先上代码:
pwd = os.getcwd() # 获得当前工作目录 filePath = 'C:\Users\Administrator\Desktop\Course comments\Number\\' + category # 得到该分类的所有课程 file_course_list = os.listdir(filePath) # print len(file_course_list) # 去掉.csv后缀 courses_name = [file_course.split('.')[0] for file_course in file_course_list] for course_name in courses_name: if course_name not in clean_course: clean_course.append(course_name)
#删除指定路径的csv文件
name = os.path.join(course_name+'.csv') os.remove(os.path.join(filePath,name)) print name
本文介绍了一种使用Python批量处理指定目录下CSV文件的方法。通过获取当前工作目录及特定路径下的所有课程评论文件,实现对这些文件的遍历并去除重复项。最后,演示了如何删除指定路径的CSV文件。

1058

被折叠的 条评论
为什么被折叠?



