[Tutor] extract specific column
Matt Williams
mhw at doctors.org.uk
Wed Oct 12 21:57:42 CEST 2011
On 12/10/2011 18:21, Anna Olofsson wrote:
> Hi,
>
> I'm a beginner at python and I'm trying to extract a specific column
> from a txt file ( see attached file).
>
> In the attached file I want to extract the entire column/pph2_prob
> /(i.e. column 16). But I want to get all the values from that column
> without the headline /pph2_prob.
>
> /How do I accomplish that?
>
> Best,
> Anna
>
Dear Anna,
Using the CSV module should work.
Something along the lines of (untested):
inLines = CSV.DictReader("/path/to/myfile.csv")
data = []
for a in inLines:
data.append(a)
for line in data:
print line["/pph2_prob/"]
Once you've got that working you just need to put the results in a file,
instead of printing them.
On a practical note (and there may be many reasons why not to), it might
be easier to open in a spreadsheet and take the data from there....
HTH,
Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111012/43b0699b/attachment.html>
More information about the Tutor
mailing list