我有許多具有相同列的不同名稱的選項卡的 excel 表,我需要將所有這些選項卡合并到一個 df 中并創建一個新列“佇列”以將每個值宣告到它的佇列中。
這里的問題是我不能一次在所有選項卡中執行此操作
原單

預期的表


uj5u.com熱心網友回復:
盡管您需要修復作業簿位置,但這應該可以作業。
這會將作業表名稱添加到 dict 中的 DataFrames 中,然后將 DataFrames 合并為一個。
import pandas as pd
workbook_location = 'Book1.xlsx'
sheets = ['Sheet1', 'Sheet2']
# sheets = ['ALMB-After Sales', 'ALMB-Corp', 'ALMB-Sales', 'CS', 'ALMB-OGOV', 'Flights', 'Retail', 'Sales']
inbound_new_calls = pd.read_excel(workbook_location, sheet_name = sheets)
for sheet, values in inbound_new_calls.items():
values['Queue'] = sheet
pd.concat(inbound_new_calls).groupby(['Queue', 'Date'])['Offered'].sum()
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/450696.html
標籤:Python python-3.x 熊猫
上一篇:計數符號(熊貓資料框)
