def modify_csv_rows(input_url=PROJ_ROOT+'data/data.csv', output_url=PROJ_ROOT+'data/modified_data.csv'):
print("Transforming initial data csv")
with open(output_url, 'w') as new:
newWriter = csv.writer(new, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
with open(input_url) as csvfile:
newWriter.writerow(['Source Port', 'Destination Port', 'Eth', 'Source', 'Destination', 'Protocol', 'IP_Flags', 'Length', 'Protocols in frame', 'Time', 'tcp_Flags', 'TCP Segment Len', 'udp_Length'])
first = True
for row in csv.reader(csvfile, delimiter=',', quotechar='"'):
if first == True:
first = False
continue
if row[2]:
row.pop(0)
row.pop(0)
else:
row.pop(2)
row.pop(2)
newWriter.writerow(row)
print("Csv row modification complete\n##############################")
评论列表
文章目录