Python Forum

Full Version: Function to skip meta data in a .csv file using Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
        break 
The 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 df
The meta data in the .csv file looks as follows:

https://i.stack.imgur.com/uS4zJ.jpg
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