当我试图使用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发布于 2017-02-09 18:21:56
这应有助于:
closest.to_frame().T或者:
index = group['helper'].idxmin()
closest = group.loc[index:index]https://stackoverflow.com/questions/42144027
复制相似问题