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
  To fetch and iterate data from CSV file using python vyom1109 3 1,815 Aug-05-2024, 10:05 AM
Last Post: Pedroski55
  Why is the 'meta description' html tag not translated? Melcu54 2 2,001 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,491 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  need to skip password prompt, continue... tester_V 2 2,588 Oct-19-2021, 05:49 PM
Last Post: tester_V
  Delimiters - How to skip some html tags from being translate Melcu54 0 2,559 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,765 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,399 Dec-21-2020, 03:24 PM
Last Post: Gribouillis
  How to use the count function from an Excel file using Python? jpy 2 7,549 Dec-21-2020, 12:30 AM
Last Post: jpy
  Databricks, Python Notebook Data file use issue khalid2200 0 2,527 Nov-25-2020, 03:36 AM
Last Post: khalid2200
  How to skip a folder directory in a loop mfkzolo 2 20,001 Nov-18-2020, 07:56 AM
Last Post: mfkzolo

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.