wolfvoid's picture
Upload folder using huggingface_hub
2572fca verified
Raw
History Blame Contribute Delete
891 Bytes
import os
import pandas as pd
def save_csv_files(folder_path):
# 遍历文件夹及其子文件夹
for root, dirs, files in os.walk(folder_path):
for filename in files:
# 检查文件是否为CSV文件
if filename.endswith(".csv"):
file_path = os.path.join(root, filename)
try:
# 读取CSV文件
df = pd.read_csv(file_path)
# 重新保存CSV文件(覆盖原文件)
df.to_csv(file_path, index=False, encoding="utf-8-sig")
print(f"Re-saved file: {file_path}")
except Exception as e:
print(f"Error processing file {file_path}: {e}")
# 指定要处理的文件夹路径
folder_path = input("请输入要处理的文件夹路径:")
save_csv_files(folder_path)