I want to read some numbers from a file which are, which I am unable to read in two lists for further calculation like Mean and STDEV.
0.0000000 0.0000005 0.0100000 0.1675796 0.0200000 0.2042502 0.0300000 0.2064999 0.0400000 0.2237432 0.0500000 0.2245723 0.0600000 0.2365732 0.0700000 0.2433299 0.0800000 0.2556339 0.0900000 0.2569953 0.1000000 0.2658122 0.1100000 0.2718526 0.1200000 0.2741648

import os 

directory= "/media/quinn/Joker/post_analysis/KBH00"

for x in range (252, 256):
    os.chdir(directory + str(x) +'/')
    print(os.getcwd())
    with open ('rmsd.xvg', 'r') as rmsd:
      line_19_to_end = rmsd.readlines()[18:]
      print("Values of RMSD are:")
      for line in line_19_to_end:
        print("%s" %(line))

1 Answers

0
Shijith On

When you are iterating add all values at the 0th position to a new list col1 and 1st position to another list col2, after conferring each values to float.

import os 

directory= "/media/quinn/Joker/post_analysis/KBH00"

for x in range (252, 256):
    os.chdir(directory + str(x) +'/')
    print(os.getcwd())
    col1,col2=[],[]
    with open ('rmsd.xvg', 'r') as rmsd:
      line_19_to_end = rmsd.readlines()[18:]
      print("Values of RMSD are:")
      for line in line_19_to_end:
        print("%s" %(line))
        line = list(map(float, line.split()))
        col1.append(line[0])
        col2.append(line[1])
print(col1,'\n',col2)