仅从数据框中获取数字

时间:2019-04-30 15:51:52

标签: python pandas

我的数据框只有一列:

                                   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等...,但我得到的不仅仅是数字。

2 个答案:

答案 0 :(得分:1)

df.values.squeeze().tolist()

如果您想要更好的格式:

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

答案 1 :(得分:0)

选择该列并将其转换为列表,这样可以解决您的问题:

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