Skip to content

Instantly share code, notes, and snippets.

@nsuvorov83
Last active October 11, 2021 15:53
Show Gist options
  • Select an option

  • Save nsuvorov83/45a89c679326719be140022911c266b8 to your computer and use it in GitHub Desktop.

Select an option

Save nsuvorov83/45a89c679326719be140022911c266b8 to your computer and use it in GitHub Desktop.
from openpyxl import load_workbook
import pandas as pd
def load_df_table(filename, worksheet, tablename):
wb = load_workbook(filename)
ws = wb[worksheet]
dfs = {}
for table_name, value in ws.tables.items():
table = ws[value]
header, *body = [[cell.value for cell in row]
for row in table]
df = pd.DataFrame(body, columns=header)
if table_name == tablename: return df
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment