第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python編輯多個工作表

Python編輯多個工作表

慕森王 2023-10-06 19:28:27
我想編輯同一 Excel 文件中存在的多個工作表,然后保存所做的調(diào)整。這些工作表具有相同的列標(biāo)題,稱為貸方和借方。我創(chuàng)建的代碼如下:import pandas as pdimport numpy as npclass blah:    def __init__(self, path, file_in, file_out):        self.path = path        self.file_inviato = file_in        self.file_out = file_out            def process_file(self):        df = pd.read_excel(self.path + self.file_in, sheet_name=None, skiprows=4)                      ****Here is where I am struggling in amending both worksheets at the same time****              #  df = df.columns.str.strip()       #  df['Col1'] = np.where((df['Col2'] == 'KO') | (df['Col2'] == 'OK'), 0, df['Col1'])                writer = pd.ExcelWriter(self.path + self.file_out, engine='xlsxwriter')                for sheet_name in df.keys():            df[sheet_name].to_excel(writer, sheet_name=sheet_name, index=False)                    writer.save()    b = blah('path....',         'file in....xlsx',         'file out.xlsx')b.process_file()
查看完整描述

1 回答

?
侃侃無極

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個贊

找到了解決方法:


for sheet_name in df.keys():

            df[sheet_name] = df[sheet_name].rename(columns=lambda x: x.strip())



            df[sheet_name]['Col1'] = np.where((df[sheet_name]['Col2'] == 'KO') | 

                                               (df[sheet_name]['Col2'] == 'OK'), 0, df[sheet_name]['Col1'])



查看完整回答
反對 回復(fù) 2023-10-06
  • 1 回答
  • 0 關(guān)注
  • 112 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號