Python: How to read excel files and skip title and information

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Python: How to read excel files and skip title and information



I am trying to read excel files in python, some of the files have information in the first few rows before the table. On of the columns of the tables is "cola". I would like to read the files where "cola" is found. Other files have the columns in the first row. When I run the following codes, it gives me an error: "Stopiteration". I don't know what I am doing wrong.


import pandas as pd
import os
import itertools as it
#import shutil

rootdir = r"C:\location"
for fname in os.listdir(rootdir):
file_path = os.path.join(rootdir,fname)
with open(file_path) as fp:
skip = next(it.ifilter(
lambda x: x[1].startswith('cola'),enumerate(fp)))[0]
if fname.endswith(".xlsx") or fname.endswith(".xls") or fname.endswith(".xlsm"):
print (os.path.join(rootdir,fname))
df = pd.read_excel(file_path, skiprows=skip)









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS