2017-02-09 6 views
0

Pandasを使用して列の中で最小の値にインデックスを付けると、DataFrameが1行のDataFrameではなくオブジェクトに変換されます。たとえ単一行であっても、DataFrameに戻したいと思います。Python/Pandas:Idxとix

for j in Amount_ref: 
    group['helper'] = np.abs(group['Amount'] - j) 
    closest = group.ix[group['helper'].idxmin()] 
    print(closest) 

これは私が取得しています出力は次のようになります。

LoanAgreementID E2502C04-DBC3-E611-8126-06CAB7997043 
Amount           566.12 
TransactionDate    2016-12-16 14:00:20.243000 
ContactID   001A29DC-9253-E611-8126-06CAB7997043 
PaymentType           NaN 
CashLedgerType          5 
KeyValue_String         Cheque 
KeyValue_String         None 
AutoNumber          54980 
IssueDate       2016-12-15 00:00:00 
helper            0 
Name: 2, dtype: object 

答えて

2

これは役立つはず:

closest.to_frame().T 

か:

index = group['helper'].idxmin() 
closest = group.loc[index:index] 
+0

本当にありがとうございましたマイク! –

関連する問題