I am a Python (2.75) neophyte and need to reformat a large data file. A sample is below:

P1 01 01 1991 100.00
P1 01 01 1992 111.30
P1 01 01 1993 97.58
I1 01 01 1991 0.0
I1 01 01 1992 20.0
I1 01 01 1993 32.4

I need each new value in the first column to become a row with the remaining duplicates removed and with a space between each group:

NAME P1
01 01 1991 100.00 1.81 14.34 0.0
01 01 1992 111.30 2.34 31.65 0.0
01 01 1993 97.58 2.93 38.16 0.0

NAME I1
01 01 1991 0.0 0.0 0.0 101.5
01 01 1992 0.0 0.0 0.0 112.2
01 01 1993 0.0 0.0 0.0 687.3

I know how to pop out a column but this is beyond my current skills. Thanks for any help.

Where does all the additional data come from?

Excel

a = open(out_file,"w")
t = file(in_file,"r").readlines()

well=''
for row in t:
    s= row.strip().split(' ')
    if s[0]==well:
        a.write('%10s %10s %10s %10s \n' % (s[1],s[2],s[3],s[4]))
        # initially skips to next statement
    else:
        a.write('NAME %10s \n' % (s[0]))
        a.write('%10s %10s %10s %10s \n' % (s[1],s[2],s[3],s[4]))  
        well=s[0]  # sets well variable so if statement now invoked
a.close()  
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.