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

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

通過與以前的標(biāo)題名稱連接來重命名 pandas 中的列標(biāo)題

通過與以前的標(biāo)題名稱連接來重命名 pandas 中的列標(biāo)題

蝴蝶刀刀 2023-10-26 16:54:28
我有一組列名稱,其中名稱描述多次存在。['Sl.No', 'Job', 'Description', 'Vendor', 'Description', 'WO No',       'Accounting Center ', 'Description', 'Nature Of Work', 'WO Type',       'WO Date', 'WO From Date', 'WO To Date', 'Bill No', 'Running Bill No',       'Bill Date', 'Bill Status', 'Voucher No', 'Voucher Date',       'Bank \nVoucher No', 'Bank Voucher\n Date', ' Paid Amount', 'Currency',       'WO Amt', 'Bill Amt', 'Service Tax Amt', 'VAT Amt', 'Total Tax \nAmt',       ' Advance Amt', 'Gross Amt', 'Deduction Amt', 'Net Amt']我希望名稱“Description”與其后面的任何標(biāo)頭名稱連接起來例如“Job”、“Description”將變?yōu)椤癑ob_Description”“Vendor”、“Description”將變?yōu)椤癡endor_Description”等我需要一個(gè)不引入任何硬編碼的邏輯['Sl.No', 'Job', 'Job_Description', 'Vendor', 'Vendor_Description',....]
查看完整描述

3 回答

?
皈依舞

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個(gè)贊

你需要找出哪里Description存在using?pd.Series.eq,然后使用pd.Index.to_series,這樣我們才能使用pd.Series.shift。

cols = df.columns.to_series()

m = cols.eq('Description') #would mark True where value is `Description`

out = cols.shift().str.strip().str.replace('\s+','_') + '_' + cols

out[~m] = cols

out.to_list()


['Sl.No', 'Job', 'Job_Description', 'Vendor', 'Vendor_Description', 'WO No',

?'Accounting Center ', 'Accounting_Center_Description', 'Nature Of Work',

?'WO Type', 'WO Date', 'WO From Date', 'WO To Date', 'Bill No', 'Running Bill No',

?'Bill Date', 'Bill Status', 'Voucher No', 'Voucher Date', 'Bank \nVoucher No',

?'Bank Voucher\n Date', ' Paid Amount', 'Currency', 'WO Amt', 'Bill Amt',

?'Service Tax Amt', 'VAT Amt', 'Total Tax \nAmt', ' Advance Amt', 'Gross Amt',

?'Deduction Amt', 'Net Amt']


查看完整回答
反對(duì) 回復(fù) 2023-10-26
?
達(dá)令說

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超6個(gè)贊

讓cols成為您原始列表的名稱。那么代碼可能是:


D = "Description"


previous_current = zip([None] + cols[:-1], cols)

df.columns = [curr if curr != D else prev + "_" + D  for prev, curr in previous_current]

結(jié)果:


>>> df.columns

Index(['Sl.No', 'Job', 'Job_Description', 'Vendor', 'Vendor_Description',

       'WO No', 'Accounting Center ', 'Accounting Center _Description',

       'Nature Of Work', 'WO Type', 'WO Date', 'WO From Date', 'WO To Date',

       'Bill No', 'Running Bill No', 'Bill Date', 'Bill Status', 'Voucher No',

       'Voucher Date', 'Bank \nVoucher No', 'Bank Voucher\n Date',

       ' Paid Amount', 'Currency', 'WO Amt', 'Bill Amt', 'Service Tax Amt',

       'VAT Amt', 'Total Tax \nAmt', ' Advance Amt', 'Gross Amt',

       'Deduction Amt', 'Net Amt'],

      dtype='object')

說明:


我們構(gòu)建了一些作為對(duì)列表的東西(previous, current):


>>> previous_current = zip([None] + cols[:-1], cols)

>>> list(previous_current)

[(None, 'Sl.No'),

 ('Sl.No', 'Job'),

 ('Job', 'Description'),

 ('Description', 'Vendor'),

 ('Vendor', 'Description'),

 ('Description', 'WO No'),

 ('WO No', 'Accounting Center '),

 ('Accounting Center ', 'Description'),

 ('Description', 'Nature Of Work'),

 ('Nature Of Work', 'WO Type'),

 ('WO Type', 'WO Date'),

 ('WO Date', 'WO From Date'),

 ('WO From Date', 'WO To Date'),

 ('WO To Date', 'Bill No'),

 ('Bill No', 'Running Bill No'),

 ('Running Bill No', 'Bill Date'),

 ('Bill Date', 'Bill Status'),

 ('Bill Status', 'Voucher No'),

 ('Voucher No', 'Voucher Date'),

 ('Voucher Date', 'Bank \nVoucher No'),

 ('Bank \nVoucher No', 'Bank Voucher\n Date'),

 ('Bank Voucher\n Date', ' Paid Amount'),

 (' Paid Amount', 'Currency'),

 ('Currency', 'WO Amt'),

 ('WO Amt', 'Bill Amt'),

 ('Bill Amt', 'Service Tax Amt'),

 ('Service Tax Amt', 'VAT Amt'),

 ('VAT Amt', 'Total Tax \nAmt'),

 ('Total Tax \nAmt', ' Advance Amt'),

 (' Advance Amt', 'Gross Amt'),

 ('Gross Amt', 'Deduction Amt'),

 ('Deduction Amt', 'Net Amt')]

然后我們迭代它,并通過該對(duì)的第二個(gè)元素(當(dāng)前列標(biāo)簽)我們決定

  • 是否保持原樣,或者

  • 將其附加前一列的標(biāo)簽(該對(duì)的第一個(gè)元素)。


查看完整回答
反對(duì) 回復(fù) 2023-10-26
?
慕碼人2483693

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊

讓cols成為您原始列表的名稱。那么代碼可能是:


D = "Description"


previous_current = zip([None] + cols[:-1], cols)

df.columns = [curr if curr != D else prev + "_" + D  for prev, curr in previous_current]

結(jié)果:


>>> df.columns

Index(['Sl.No', 'Job', 'Job_Description', 'Vendor', 'Vendor_Description',

       'WO No', 'Accounting Center ', 'Accounting Center _Description',

       'Nature Of Work', 'WO Type', 'WO Date', 'WO From Date', 'WO To Date',

       'Bill No', 'Running Bill No', 'Bill Date', 'Bill Status', 'Voucher No',

       'Voucher Date', 'Bank \nVoucher No', 'Bank Voucher\n Date',

       ' Paid Amount', 'Currency', 'WO Amt', 'Bill Amt', 'Service Tax Amt',

       'VAT Amt', 'Total Tax \nAmt', ' Advance Amt', 'Gross Amt',

       'Deduction Amt', 'Net Amt'],

      dtype='object')

說明:


我們構(gòu)建了一些作為對(duì)列表的東西(previous, current):


>>> previous_current = zip([None] + cols[:-1], cols)

>>> list(previous_current)

[(None, 'Sl.No'),

 ('Sl.No', 'Job'),

 ('Job', 'Description'),

 ('Description', 'Vendor'),

 ('Vendor', 'Description'),

 ('Description', 'WO No'),

 ('WO No', 'Accounting Center '),

 ('Accounting Center ', 'Description'),

 ('Description', 'Nature Of Work'),

 ('Nature Of Work', 'WO Type'),

 ('WO Type', 'WO Date'),

 ('WO Date', 'WO From Date'),

 ('WO From Date', 'WO To Date'),

 ('WO To Date', 'Bill No'),

 ('Bill No', 'Running Bill No'),

 ('Running Bill No', 'Bill Date'),

 ('Bill Date', 'Bill Status'),

 ('Bill Status', 'Voucher No'),

 ('Voucher No', 'Voucher Date'),

 ('Voucher Date', 'Bank \nVoucher No'),

 ('Bank \nVoucher No', 'Bank Voucher\n Date'),

 ('Bank Voucher\n Date', ' Paid Amount'),

 (' Paid Amount', 'Currency'),

 ('Currency', 'WO Amt'),

 ('WO Amt', 'Bill Amt'),

 ('Bill Amt', 'Service Tax Amt'),

 ('Service Tax Amt', 'VAT Amt'),

 ('VAT Amt', 'Total Tax \nAmt'),

 ('Total Tax \nAmt', ' Advance Amt'),

 (' Advance Amt', 'Gross Amt'),

 ('Gross Amt', 'Deduction Amt'),

 ('Deduction Amt', 'Net Amt')]


查看完整回答
反對(duì) 回復(fù) 2023-10-26
  • 3 回答
  • 0 關(guān)注
  • 240 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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