从数据框中获取数字

2024-04-19 00:30:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一列的数据帧:

                                   0
UPB                         2.260241e+08
Voluntary Payoffs           0.000000e+00
Involuntary Payoffs         3.169228e+06
Loan Loss                   0.000000e+00
Cost Basis                  2.221221e+08
Cost Basis Liquidated       3.149118e+06
Escrow Advances             0.000000e+00
Corp Advances               0.000000e+00
Loan Count                  6.670000e+02
Loan Count of Paying Loans  5.510000e+02

我只想把数字写进一个单子里。我试过用iloc,ix等等。。。但我得到的不仅仅是数字


Tags: 数据countbasis数字costcorploanloss
2条回答

选择列并将其转换为类似的列表可以解决您的问题:

df = pd.DataFrame({"0": [1,2,3]})
print(list(df["0"]))
df.values.squeeze().tolist()

如果你想要更好的格式:

df.values.apply(lambda x: np.round(x, 2)).squeeze().tolist()

相关问题 更多 >