Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79247 > unrolled thread

Write list to new column in existent csv

Started byTal Bar-Or <tbaror@gmail.com>
First post2014-10-17 09:56 -0700
Last post2014-10-17 20:08 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Write list to new column in existent csv Tal Bar-Or <tbaror@gmail.com> - 2014-10-17 09:56 -0700
    Re: Write list to new column in existent csv Peter Otten <__peter__@web.de> - 2014-10-17 20:08 +0200

#79247 — Write list to new column in existent csv

FromTal Bar-Or <tbaror@gmail.com>
Date2014-10-17 09:56 -0700
SubjectWrite list to new column in existent csv
Message-ID<a888d7a9-efe5-4887-a495-201c9002232e@googlegroups.com>
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,,,,,,,,

[toc] | [next] | [standalone]


#79249

FromPeter Otten <__peter__@web.de>
Date2014-10-17 20:08 +0200
Message-ID<mailman.14948.1413569341.18130.python-list@python.org>
In reply to#79247
Tal Bar-Or wrote:

> 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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web