Discussion:
Write list to new column in existent csv
Tal Bar-Or
2014-10-17 16:56:17 UTC
Permalink
Hello Group,

I am tryin to figure how to write a list i have as follows

['info', '19987???445 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1\n', '445???19987 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1460 WS=64 SACK_PERM=1\n', '19987???445 [ACK] Seq=1 Ack=1 Win=65536 Len=0\n', 'Negotiate Protocol Request\n', '[TCP Retransmission] Negotiate Protocol Request\n', '445???19987 [ACK] Seq=1 Ack=160 Win=1049536 Len=0\n', 'Negotiate Protocol Response\n', 'Negotiate Protocol Request\n', 'Negotiate Protocol Response\n', 'Session Setup Request, NTLMSSP_NEGOTIATE\n', 'Session Setup Response, Error: STATUS_MORE_PROCESSING_REQUIRED, NTLMSSP_CHALLENGE\n', 'Session Setup Request, NTLMSSP_AUTH, User: GEFEN\\tbaror\n', '445???19987 [ACK] Seq=768 Ack=1016 Win=1049728 Len=0\n', 'Session Setup Response\n', 'Tree Connect Request Tree: \\\\media.isilon.gefen.local\\Media\n', 'Tree Connect Response\n', 'Create Request File: New Text document.txt\n', 'Create Response File: New Text document.txt\n', 'GetInfo Request FS_INFO/SMB2_FS_INFO_01 File: New Text document.txt;GetInfo Request FS_INFO/SMB2_FS_INFO_05 File: New Text document.txt\n']


To a a csv to for example the 3rd column , i am really got stacked here i tried few codes with csv.writerow() but didn't got it work ,will really appreciate if someone could help me with that
Please advice
Thanks

The csv
ip.src,ip.dst,smb.file,smb2.filename,smb.path,smb2.tree,smb.time,smb2.time,smb.cmd,smb2.cmd,tcp.time_delta,tcp.analysis.ack_rtt,tcp.analysis.ack_lost_segment,tcp.analysis.duplicate_ack,tcp.analysis.lost_segment,tcp.analysis.retransmission,tcp.analysis.out_of_order,tcp.analysis.window_full,tcp.analysis.window_update,tcp.analysis.zero_window
172.18.2.54,172.18.5.64,,,,,,,,,0,,,,,,,,,
172.18.5.64,172.18.2.54,,,,,,,,,0.003322,0.003322,,,,,,,,
172.18.2.54,172.18.5.64,,,,,,,,,0.000029,0.000029,,,,,,,,
172.18.2.54,172.18.5.64,,,,,,,114,,0.000084,,,,,,,,,
172.18.2.54,172.18.5.64,,,,,,,114,,0.300507,,,,,1,,,,
172.18.5.64,172.18.2.54,,,,,,,,,0.000114,0.300621,,,,,,,,
172.18.5.64,172.18.2.54,,,,,,,,0,0.000266,,,,,,,,,
172.18.2.54,172.18.5.64,,,,,,,,0,0.000092,0.000092,,,,,,,,
172.18.5.64,172.18.2.54,,,,,,0.000192,,0,0.000192,0.000192,,,,,,,,
172.18.2.54,172.18.5.64,,,,,,,,1,0.000589,0.000589,,,,,,,,
172.18.5.64,172.18.2.54,,,,,,0.001788,,1,0.001788,0.001788,,,,,,,,
172.18.2.54,172.18.5.64,,,,,,,,1,0.000193,0.000193,,,,,,,,
172.18.5.64,172.18.2.54,,,,,,,,,0.005582,0.005582,,,,,,,,
172.18.5.64,172.18.2.54,,,,,,0.008014,,1,0.002432,,,,,,,,,
172.18.2.54,172.18.5.64,,,,\\media.isilon.gefen.local\Media,,,,3,0.000203,0.000203,,,,,,,,
172.18.5.64,172.18.2.54,,,,,,0.000458,,3,0.000458,0.000458,,,,,,,,
172.18.2.54,172.18.5.64,,New Text document.txt,,\\media.isilon.gefen.local\Media,,,,5,0.000189,0.000189,,,,,,,,
172.18.5.64,172.18.2.54,,,,\\media.isilon.gefen.local\Media,,0.000274,,5,0.000274,0.000274,,,,,,,,
Peter Otten
2014-10-17 18:08:42 UTC
Permalink
Post by Tal Bar-Or
I am tryin to figure how to write a list i have as follows
To a a csv to for example the 3rd column , i am really got stacked here i
tried few codes with csv.writerow() but didn't got it work ,will really
appreciate if someone could help me with that Please advice Thanks
Here's a sketch:

Open the source file using a csv.reader(); open the destination file using a
csv.writer().

Use zip() and a for-loop to iterate over the new column and the rows in the
source.

Insert the new field into the source row, e. g. row.insert(3, field)

Use writerow() to write the modified row.

Loading...