#打开源文件
reader_csv = pd.read_table(file_path,iterator=True,names=field_name)
loop = True
row_csv_data = []
while loop:
try:
#分批获取数据
chunk = reader_csv.get_chunk(chunkSize)
#遍历分批数据中的每一行
for row in chunk.iterrows():
row_list = row[1]["saddr"].split(",")
list1 = [1,2,3,4]
#如果IP字段存在,则查询geolite的地理位置
if row_list[1]:
ip_address = row_list[1]
#row_csv_data.append(row_list+list1)
geolite_data = ip_get_location(ip_address)
if geolite_data is not None:
#print(type(geolite_data))
row_csv_data.append(row_list+geolite_data)
except Exception as err:
loop = False
print("loop is stoped! {}".format(err))
with open(new_file_path,'w',newline='')as f:
f_csv = csv.writer(f)
f_csv.writerows(row_csv_data)
【无标题】
最新推荐文章于 2024-11-18 12:05:16 发布