Python Forum
Function to skip meta data in a .csv file using Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function to skip meta data in a .csv file using Python
#1
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
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I skip the first row in the dataframe? dee 5 85 Apr-27-2026, 02:07 PM
Last Post: dee
  To fetch and iterate data from CSV file using python vyom1109 3 1,887 Aug-05-2024, 10:05 AM
Last Post: Pedroski55
  Why is the 'meta description' html tag not translated? Melcu54 2 2,037 Oct-15-2022, 10:55 PM
Last Post: Larz60+
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 2,538 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  need to skip password prompt, continue... tester_V 2 2,650 Oct-19-2021, 05:49 PM
Last Post: tester_V
  Delimiters - How to skip some html tags from being translate Melcu54 0 2,600 May-26-2021, 06:21 AM
Last Post: Melcu54
  How to skip to a different line while importing a different script kat_gamer 2 3,831 Feb-03-2021, 04:10 AM
Last Post: deanhystad
  xml file creation from an XML file template and data from an excel file naji_python 1 3,456 Dec-21-2020, 03:24 PM
Last Post: Gribouillis
  How to use the count function from an Excel file using Python? jpy 2 7,853 Dec-21-2020, 12:30 AM
Last Post: jpy
  Databricks, Python Notebook Data file use issue khalid2200 0 2,557 Nov-25-2020, 03:36 AM
Last Post: khalid2200

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020