Vinfall bu gisti düzenledi . Düzenlemeye git
Değişiklik yok
Vinfall bu gisti düzenledi . Düzenlemeye git
Değişiklik yok
Vinfall bu gisti düzenledi . Düzenlemeye git
1 file changed, 41 insertions
vndb-merge.py(dosya oluşturuldu)
@@ -0,0 +1,41 @@ | |||
1 | + | #!/usr/bin/python3 | |
2 | + | ||
3 | + | import pandas as pd | |
4 | + | import glob | |
5 | + | import os | |
6 | + | import csv | |
7 | + | ||
8 | + | ||
9 | + | def merge_csv_files(file_pattern, output_prefix): | |
10 | + | # 获取所有CSV文件,并按文件名顺序排序 | |
11 | + | csv_files = glob.glob(file_pattern) | |
12 | + | ||
13 | + | # 按照文件名的顺序(即按ls输出的顺序)进行排序 | |
14 | + | csv_files.sort(key=lambda x: os.path.basename(x)) | |
15 | + | ||
16 | + | # 创建一个空的DataFrame用于合并 | |
17 | + | combined_df = pd.DataFrame() | |
18 | + | ||
19 | + | # 遍历所有CSV文件 | |
20 | + | for file in csv_files: | |
21 | + | df = pd.read_csv(file) | |
22 | + | combined_df = pd.concat([combined_df, df], ignore_index=True) | |
23 | + | ||
24 | + | # 提取日期 | |
25 | + | if csv_files: | |
26 | + | first_file = csv_files[0] | |
27 | + | date_str = first_file.split("-")[-1][:8] # 提取前8个字符作为日期 (YYYYMMDD) | |
28 | + | output_filename = f"{output_prefix}-{date_str}.csv" | |
29 | + | ||
30 | + | # 保存合并后的DataFrame到新的CSV文件,保留引号 | |
31 | + | combined_df.to_csv(output_filename, index=False, quoting=csv.QUOTE_ALL) | |
32 | + | print(f"合并完成,文件名为: {output_filename}") | |
33 | + | else: | |
34 | + | print(f"没有找到符合条件的CSV文件: {file_pattern}") | |
35 | + | ||
36 | + | ||
37 | + | # 处理 vndb-lengthvotes-export- 开头的文件 | |
38 | + | merge_csv_files("vndb-lengthvotes-export-*.csv", "vndb-lengthvotes-export") | |
39 | + | ||
40 | + | # 处理 vndb-list-export- 开头的文件 | |
41 | + | merge_csv_files("vndb-list-export-*.csv", "vndb-list-export") |
Daha yeni
Daha eski