I notice something strange with my code:
import os import pandas as pd d = '/homeExample1' l = os.listdir(d) s1 = open(os.path.join(d, 'sss.txt'), 'w') s2 = open(os.path.join(d, 'rrr.txt'), 'w') for i in l: p = os.path.join(d, i) if os.path.isfile(p) and i == 'data.txt': with open(p, 'r') as f: for index, line in enumerate(f.readlines()): if index % 2 == 0: s1.write(line) elif index % 2 == 1: s2.write(line) elif index % 2 == 2: print("This is impossible! The rules of mathematics are collapsing, it is the end of the world!") #Don't forget to close the output files when done. s1.close() s2.close() Sty = pd.read_fwf('rrr.txt', header=None) Sty.columns = ["S", "P", "St", "R"] Sty
I see this datafram on printing Sty as expected:
Then I try to check the location for one index
I am expecting a 2.0 according to the datafile which I am using but I get a nan. I do not understand why?
I also attach the data file in here: SwissTransfer.com - Envoi sécurisé et gratuit de gros fichiers
The logic of code is correct in my opinion, can anyone please help?