import os
import pandas as pd # 导入pandas库用于处理CSV文件
# 假设这些文件名(包括扩展名)已经在列表中了
file_names = [
"28679099999_PETROPAVLOVSK_KAZAKHSTAN_(69.15,54.833).csv",
"28766099999_BLAGOVESHCHENKA_KAZAKHSTAN_(66.9666666,54.3666666).csv",
"28785099999_VOZVISHEN_SOVKHOZ_KAZAKHSTAN_(70.917,54.433).csv",
"28867099999_SARYKOL_KAZAKHSTAN_(65.55,53.3166666).csv",
"28877099999_VOLODARSKOE_KAZAKHSTAN_(68.1,53.317).csv",
"28879099999_KOKSHETAY_KAZAKHSTAN_(69.3833333,53.2833333).csv",
"28886099999_KZIL TUS SOVKHOZ_KAZAKHSTAN_(72.367,53.633).csv",
"28952099999_KOSTANAY_KAZAKHSTAN_(63.6166666,53.2166666).csv",
"28966099999_RUZAEVKA_KAZAKHSTAN_(66.9666666,52.8166666).csv",
# ... 以及其他文件名,确保扩展名是.csv
]
# 设置您的文件夹路径
folder_path = 'D:/天翼云盘下载/D/noaa/1995' # 替换为您的文件夹实际路径
output_folder = 'D:/天翼云盘下载/D/noaa提取的/1995' # 替换为您的输出文件夹实际路径
# 确保输出文件夹存在
if not os.path.exists(output_folder):
os.makedirs(output_folder)
# 遍历文件名列表,并检查它们是否存在于文件夹中
for file_name in file_names:
full_file_path = os.path.join(folder_path, file_name)
if os.path.exists(full_file_path):
print(f"Found file: {full_file_path}")
# 读取CSV文件内容
df = pd.read_csv(full_file_path)
# ... 在这里可以对数据框df进行处理 ...
# 如果需要,可以更改输出文件名(但在这里我们保留原始文件名)
output_file_path = os.path.join(output_folder, file_name)
# 将数据框写入CSV文件(如果文件已存在,这将会覆盖它)
df.to_csv(output_file_path, index=False) # index=False表示不保存行索引
print(f"Saved to: {output_file_path}")
else:
print(f"File not found: {file_name}")
从文件夹中提取自己需要得csv
于 2024-05-13 18:57:48 首次发布