processing csv with python

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010643777/article/details/81914369

 I need to extract out data from wireshark captured data. And I already extracted out these collected data about a specific IP. And the final data that I need is about rtt. And the some lines on the rtt data is null value and I tried it with Excel to filter out these lines with CTRL+G operation. The excel works slowly and some times was stuck without any response.
 The format of my data is the following:

Time,Source,Destination,rtt,destport,srcport
2.679784,10.0.4.1,10.0.5.2,,3333,35852
2.71042,10.0.4.1,10.0.5.2,,3333,35854
2.823876,10.0.5.2,10.0.4.1,0.144092,35852,3333
2.840817,10.0.5.2,10.0.4.1,0.130397,35854,3333
2.854966,10.0.4.1,10.0.5.2,0.03109,3333,35852
2.866116,10.0.4.1,10.0.5.2,,3333,35852
2.866121,10.0.4.1,10.0.5.2,,3333,35852
2.866209,10.0.4.1,10.0.5.2,,3333,35852
2.866211,10.0.4.1,10.0.5.2,,3333,35852

 So finally, I get the problem solved with python. Here is my code.
data_processing_csv.py:

#!/usr/bin/env python
import csv

filename = 'in.csv'
data_out="out.txt"
fileObject = open(data_out, 'w')
with open(filename) as f:
    reader = csv.reader(f)
    for row in reader:
        if(row[3]!=""):
            for i in range(len(row)):
                fileObject.write(row[i])
                fileObject.write("\t")
            fileObject.write("\n")

[1]‘module’ object has no attribute ‘reader’

猜你喜欢

转载自blog.csdn.net/u010643777/article/details/81914369