I have attached data at the bottom of this post. I have output from another program that I would like to parse in python in a reasonable way.
The output will always be in the same form, and what I would like to do is find out which "tag" has the largest value. I've labeled a truncated version of the data below (and labeled the top of the column)
0 1 2 3 4 5 6 7 8
AlII 1.6272514892aa 0.0000042282 5.85216aa 0.68792 10.741103 0.074253 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6273145922ab 0.0000129136 0.50000ab 1.41279 10.483775 0.516978 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
MgII 1.6272514892AA 0.0000000000 5.85217AA 0.00000 11.510502 3.9484 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
So what I'd like to do is parse this file in a number of ways. From the abbreviated one above I'd like to return the following:
- Largest (column 2): AlII ab: 0.0000129136
- Largest (column 4): AlII ab: 1.41279
- Largest (column 6): MgII AA: 3.9484
And I'd actually like to do the top N largest values, but for the example I'll just do the largest. I'm getting bogged down by creating new lists, and finding the indexes of these new lists. Is there some straightforward way of doing this kind of parsing? Or is it going to be a messy process?
EDIT
I've been asked to give some code showing what I've tried.
import numpy as np
analyseList = []
with open('output.ascii', 'r') as f18:
for line in f18.read().splitlines():
analyseList.append(line.split())
for column in [2, 4, 6]:
winner = analyseList[np.argmax(np.column_stack(np.array(analyseList))[column])]
print winner[0], winner[1][-2:], winner[column]
Of course this only returns the largest value (and I'd like to be able to do the N largest). Also, it just looks like I'm doing it in the least straightforward way possible.
To get the index values of the top N largest values, I can do (using the suggestion from ):
[list(analyse_array[2]).index(x) for x in heapq.nlargest(5, analyse_array[2])]
Am I doing some super-convoluted stuff?
AlII 1.6272514892aa 0.0000042282 5.85216aa 0.68792 10.741103 0.074253 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6273145922ab 0.0000129136 0.50000ab 1.41279 10.483775 0.516978 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6273482473ac 0.0000118688 2.01059ac 3.95256 10.714536 0.646238 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6273975034ad 0.0000379662 3.78319ad 5.42225 11.118654 0.683413 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6274362338ae 0.0000137972 2.17566ae 2.17134 11.105118 1.025574 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6274729985af 0.0000071899 2.59672af 1.62035 11.686851 0.218038 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6275047836ag 0.0000059328 0.56225ag 0.73486 10.908730 0.729322 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6275333529ah 0.0000063501 2.46788ah 1.66430 11.280185 0.381467 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6275811952ai 0.0000273404 4.39490ai 3.90964 11.154901 0.430842 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6276822766ak 0.0000153451 3.86075ak 1.01659 11.687808 0.302170 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6277080822al 0.0000041420 2.77773al 0.74546 11.515588 0.594305 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6277357442am 0.0000180202 3.03343am 2.97410 11.311138 0.474284 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6277884119an 0.0000100139 3.05039an 1.49107 11.218137 0.271466 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6278358107cd 0.0000488929 3.80549cd 6.28261 11.103154 1.305702 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6278657638ao 0.0000095109 4.23025ao 1.26277 11.681221 0.419769 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6279139560bq 0.0000074039 2.68827bq 1.66201 11.457767 0.630426 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6280021360cb 0.0000058565 1.55711cb 1.67734 11.188839 0.706256 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6280408039cc 0.0000168737 3.88995cc 2.74610 11.520547 0.303991 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6279628448ar 0.0000059612 4.02312ar 2.18053 11.975320 0.228508 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6280940230as 0.0000033920 0.61137as 0.37590 10.717869 0.253534 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6281299959at 0.0000035012 0.90119at 0.58387 10.833329 0.072094 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6281673440au 0.0000048884 0.50000au 0.84155 10.339533 0.191522 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
AlII 1.6282125019av 0.0000068319 7.51956av 1.17482 11.097728 0.069789 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
MgII 1.6272514892AA 0.0000000000 5.85217AA 0.00000 11.510502 0.039484 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6273145922AB 0.0000000000 0.50000AB 0.00000 11.176308 0.522596 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6273482473AC 0.0000000000 2.01060AC 0.00000 11.450444 0.591724 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6273975034AD 0.0000000000 3.78320AD 0.00000 11.803555 0.736543 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6274362338AE 0.0000000000 2.17568AE 0.00000 11.967321 0.821801 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6274729985AF 0.0000000000 2.59673AF 0.00000 12.458430 0.235348 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6275047836AG 0.0000000000 0.56231AG 0.00000 11.941490 0.332862 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6275333529AH 0.0000000000 2.46790AH 0.00000 12.037696 0.343867 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6275811952AI 0.0000000000 4.39491AI 0.00000 11.840805 0.451418 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6276822766AK 0.0000000000 3.86076AK 0.00000 12.497054 0.314167 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6277080822AL 0.0000000000 2.77775AL 0.00000 12.391999 0.522446 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6277357442AM 0.0000000000 3.03344AM 0.00000 12.112177 0.481882 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6277884119AN 0.0000000000 3.05040AN 0.00000 12.013911 0.321297 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6278358107CD 0.0000000000 3.80550CD 0.00000 12.061481 1.335432 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6278657638AO 0.0000000000 4.23025AO 0.00000 12.520703 0.551397 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6279139560BQ 0.0000000000 2.68828BQ 0.00000 12.419351 0.538659 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6280021360CB 0.0000000000 1.55713CB 0.00000 11.993443 0.736608 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6280408039CC 0.0000000000 3.88996CC 0.00000 12.272450 0.312588 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6279628448AR 0.0000000000 4.02313AR 0.00000 12.836074 0.241956 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6280940230AS 0.0000000000 0.61143AS 0.00000 11.738664 0.119798 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6281299959AT 0.0000000000 0.90123AT 0.00000 11.522748 0.084764 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6281673440AU 0.0000000000 0.50000AU 0.00000 11.179284 0.155217 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6282125019AV 0.0000000000 7.51956AV 0.00000 11.963228 0.066024 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgII 1.6282950406aw 0.0000162434 0.50000aw 18.49632 10.153640 0.769463 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 1.000E+00 0.000E+00
FeII 1.6276822766AK 0.0000000000 3.86071AK 0.00000 11.593048 0.330634 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6277080822AL 0.0000000000 2.77768AL 0.00000 11.784789 0.214666 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6277884119AN 0.0000000000 3.05033AN 0.00000 11.072150 0.276522 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6278358107CD 0.0000000000 3.80545CD 0.00000 11.147939 1.295144 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6278657638AO 0.0000000000 4.23021AO 0.00000 11.660933 0.468554 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6279139560BQ 0.0000000000 2.68821BQ 0.00000 11.427745 0.662669 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6280021360CB 0.0000000000 1.55700CB 0.00000 10.341299 3.837088 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6280408039CC 0.0000000000 3.88991CC 0.00000 11.289446 0.290091 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6279628448AR 0.0000000000 4.02308AR 0.00000 11.989071 0.212467 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6280940230AS 0.0000000000 0.61111AS 0.00000 9.766184 1.484659 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6281299959AT 0.0000000000 0.90101AT 0.00000 10.590012 0.186610 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6281673440AU 0.0000000000 0.50000AU 0.00000 10.186119 0.472566 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
FeII 1.6282125019AV 0.0000000000 7.51954AV 0.00000 11.190375 0.088965 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6272514892AA 0.0000000000 5.85216AA 0.00000 10.321950 0.459616 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6273145922AB 0.0000000000 0.50000AB 0.00000 10.097437 0.853198 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6273482473AC 0.0000000000 2.01059AC 0.00000 10.102194 1.947396 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6273975034AD 0.0000000000 3.78319AD 0.00000 11.105979 0.686387 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6274362338AE 0.0000000000 2.17566AE 0.00000 11.175948 0.814687 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6274729985AF 0.0000000000 2.59672AF 0.00000 11.548086 0.275875 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6275047836AG 0.0000000000 0.56225AG 0.00000 11.108123 0.386412 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6275333529AH 0.0000000000 2.46788AH 0.00000 11.292689 0.333124 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6275811952AI 0.0000000000 4.39490AI 0.00000 11.057781 0.453329 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6276822766AK 0.0000000000 3.86075AK 0.00000 11.265981 0.325767 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6277080822AL 0.0000000000 2.77773AL 0.00000 11.117329 0.630136 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6277357442AM 0.0000000000 3.03343AM 0.00000 10.921103 0.639479 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6277884119AN 0.0000000000 3.05039AN 0.00000 11.191087 0.159695 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6278657638AO 0.0000000000 4.23025AO 0.00000 11.504725 0.162766 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6279139560BQ 0.0000000000 2.68827BQ 0.00000 11.185086 0.780060 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6280021360CB 0.0000000000 1.55711CB 0.00000 10.744751 1.475204 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6280408039CC 0.0000000000 3.88995CC 0.00000 11.471091 0.278311 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6279628448AR 0.0000000000 4.02312AR 0.00000 11.854733 0.209241 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6280940230AS 0.0000000000 0.61137AS 0.00000 10.205223 0.810373 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6281299959AT 0.0000000000 0.90119AT 0.00000 10.823697 0.155524 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6281673440AU 0.0000000000 0.50000AU 0.00000 10.582535 0.258096 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
AlIII 1.6282125019AV 0.0000000000 7.51956AV 0.00000 10.874901 0.182424 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6272514892AA 0.0000000000 5.85217AA 0.00000 9.963618 0.199973 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6273975034AD 0.0000000000 3.78320AD 0.00000 10.008887 0.626172 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6274362338AE 0.0000000000 2.17568AE 0.00000 10.029316 0.772678 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6274729985AF 0.0000000000 2.59673AF 0.00000 10.171716 0.390966 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6275047836AG 0.0000000000 0.56231AG 0.00000 9.914891 0.378870 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6275333529AH 0.0000000000 2.46790AH 0.00000 10.075757 0.224531 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6276822766AK 0.0000000000 3.86076AK 0.00000 10.525614 0.306759 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6277080822AL 0.0000000000 2.77775AL 0.00000 10.460383 0.403447 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6277357442AM 0.0000000000 3.03344AM 0.00000 9.791121 0.536106 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6278657638AO 0.0000000000 4.23025AO 0.00000 10.746795 0.126158 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6279139560BQ 0.0000000000 2.68828BQ 0.00000 10.134445 0.921959 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6280021360CB 0.0000000000 1.55713CB 0.00000 9.964342 0.676227 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6280408039CC 0.0000000000 3.88996CC 0.00000 10.126811 0.368050 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6279628448AR 0.0000000000 4.02313AR 0.00000 10.750671 0.228670 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6280940230AS 0.0000000000 0.61143AS 0.00000 9.405961 0.588696 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6281299959AT 0.0000000000 0.90123AT 0.00000 9.292788 0.728340 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00
MgI 1.6281673440AU 0.0000000000 0.50000AU 0.00000 9.807055 0.210571 0.0000E+00QA 0.0000E+00 0 [ 0.000 0.000 0.000E+00 0.000E+00