首页 > 解决方案 > 将浮点数列表转换为熊猫中的多列浮点数

问题描述

我有pandas一列包含 1000 的列表float。但是,我不想有一列带有列表,而是希望有 1000 列的 1 float。现在,这些列表与string类型一起存储。

列表示例(裁剪):

[0.12953150272369385, 0.16092558205127716, -0.03718775138258934]

我知道可以通过遍历行并创建 1000 列并一一传递新值来做到这一点。但这会很慢。

有更快的方法吗?

标签: pythonpandas

解决方案


Put it in brackets so that you have a list of the list:

l = [0.12953150272369385, 0.16092558205127716, -0.03718775138258934]

pd.DataFrame(l)
Out: 
          0
0  0.129532
1  0.160926
2 -0.037188

pd.DataFrame([l])
Out: 
          0         1         2
0  0.129532  0.160926 -0.037188

推荐阅读