我想您可以先用^{}选择invoice_desc的子集,然后用^{}来转置它,然后用i来改变列。不需要由pd.DataFrame创建新的DataFrame。在print invoice_desc
0 1
0 Bill to \tclient
1 Billing ID xxxx-xxxx-xxxx-xxxx
2 Invoice number 3359680287
3 Issue date 31-Jan-2016
4 Due Date 01-Mar-2016
5 Currency CURR
6 Invoice subtotal 9,999,999.90
7 VAT (0%) 0.00
8 Amount due 9,999,999.90
invoice_desc2 = invoice_desc.loc[[2, 3, 4, 8],:]
invoice_desc2 = invoice_desc2.T
print invoice_desc2
2 3 4 8
0 Invoice number Issue date Due Date Amount due
1 3359680287 31-Jan-2016 01-Mar-2016 9,999,999.90
i = ['invoiceNum', 'issueDate', 'dueDate', 'invoiceSubtotal']
invoice_desc2.columns = i
print invoice_desc2
invoiceNum issueDate dueDate invoiceSubtotal
0 Invoice number Issue date Due Date Amount due
1 3359680287 31-Jan-2016 01-Mar-2016 9,999,999.90
或者先用i设置index,然后转置:
^{pr2}$