当我尝试使用Pandas索引列中的最小值时,它会将我的DataFrame转换为对象而不是具有一行的DataFrame。我想恢复到DataFrame,即使它只是一行。
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
答案 0 :(得分:2)
这应该有所帮助:
closest.to_frame().T
或:
index = group['helper'].idxmin()
closest = group.loc[index:index]