Function to skip meta data in a .csv file using Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Function to skip meta data in a .csv file using Python (/thread-11701.html) |
Function to skip meta data in a .csv file using Python - ajgardev - Jul-22-2018 I have a functioning code to skip the meta data in a .csv file using Python. However, I cannot understand what this part of the code is doing: else: if not col: continue #No columns found yet else: i+=1 #Last column found breakThe whole code is as follows: def readPandoraCSV(file): with open(file) as f: lines=f.readlines() col=0 for i in range(len(lines)): line=lines[i] if line[0:6]=='Column': col+=1 else: if not col: continue #No columns found yet else: i+=1 #Last column found break df=read_csv(file,skiprows=range(i),header=None) try: df['JDate']=df[df.columns[0]].apply(getJD) df=df.drop(df.columns[0],1) except: df['JDate']=df[df.columns[1]].apply(getJD) df=df.drop(df.columns[1],1) return dfThe meta data in the .csv file looks as follows: https://i.stack.imgur.com/uS4zJ.jpg RE: Function to skip meta data in a .csv file using Python - Larz60+ - Jul-22-2018 if col == 0 , then if not col is True.continue means skip remainder of this iteration (of loop) and continue with next break means quit loop unconditionally |