【发布时间】:2021-09-23 22:11:03
【问题描述】:
我需要从许多 Excel 工作簿中提取特定工作表。工作表在每个 Excel 工作簿中的标题完全相同。
提取后,我需要根据相应 Excel 工作簿标题的开头命名每个数据框(从每个提取的工作表创建)。 示例:对于标题为“Pizza”的工作表(每个 Excel 工作簿都相同)和标题为“Coke_2021”的 Excel 工作簿,数据框应自动命名为“Pizza_Coke”。 Excel工作簿的格式为:'Coke_2021'、'Sprite_2019'等,因此非常可预测。
我有以下代码,但卡在第 1 步(提取工作表)。
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
import pyodbc
import openpyxl
from openpyxl.utils.dataframe import dataframe_to_rows
from openpyxl import load_workbook
from openpyxl.worksheet.table import Table
import xlwings as xw
import pandas as pd
import datetime
import numpy as np
import itertools
import ntpath
import calendar
## UI - Asking user for their input and output files
root = tk.Tk()
root.withdraw()
root.databases = filedialog.askopenfilenames(initialdir = "C:/",title = "Select the location of your Soda files (you may select multiple files)", filetypes = (("Excel Files","*.xlsx"),("all files","*.*")))
db_list = root.tk.splitlist(root.databases)
【问题讨论】:
-
“标记每个数据框”是什么意思?
-
如果您的问题是第一步,为什么这会被标记为“tkinter”? tkinter 似乎与此问题无关。
标签: python excel pandas database extract