-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.py
41 lines (33 loc) · 1.15 KB
/
process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import re
import pandas as pd
# 获取当前目录
current_directory = os.getcwd()
# 获取当前目录下的所有CSV文件
csv_files = [f for f in os.listdir(current_directory) if f.endswith(".csv")]
# 提取文件名中的数字并按其排序
csv_files.sort(key=lambda x: int(re.search(r'AS(\d+)', x).group(1)) if re.search(r'AS(\d+)', x) else float('inf'))
# 读取 ip.csv 文件
file_path = 'ip.csv'
df = pd.read_csv(file_path)
# 更新 '数据中心' 列的值
df['数据中心'] = df.apply(lambda row: f"{row['数据中心']}-{row['下载速度']}", axis=1)
# 查找第一个空的CSV文件
non_empty_files = []
for csv_file in csv_files:
csv_file_path = os.path.join(current_directory, csv_file)
if os.path.getsize(csv_file_path) == 0:
# 将更新后的数据写入空的CSV文件
df.to_csv(csv_file_path, index=False)
print(f"Data written to: {csv_file}")
break
else:
non_empty_files.append(csv_file)
if non_empty_files:
print("Non-empty CSV files:")
for file in non_empty_files:
print(file)
else:
print("No non-empty CSV files found.")
# 打印更新后的数据
# print(df)