Skip to main content
 首页 » 编程设计

python之在python pandas的一列中转换多维列表

2025年05月04日11sxdcgaq8080

我想知道在 pandas 框架的单列中“翻译”多维列表是否能得到一些帮助。

我在这里找到了帮助在具有多个列的列中翻译多维列表,但我需要在一个列中翻译数据

假设我有以下列表

x=[[1,2,3],[4,5,6]] 

如果我创建一个框架,我会得到

frame=pd.Dataframe(x) 
 
0  1  2 
1  2  3 
4  5  6 

但我想要的结果应该是

0 
1 
2 
3 
4 
5 
6 

以零作为列标题。

我当然可以用 for 循环得到结果,从我的角度来看这会花费很多时间。有什么 pythonic/pandas 方法可以得到它吗?

谢谢你帮助男人

请您参考如下方法:

你可以使用np.concatenate

x=[[1,2,3],[4,5,6]] 
 
frame=pd.DataFrame(np.concatenate(x)) 
print(frame) 

输出:

    0 
0   1 
1   2 
2   3 
3   4 
4   5 
5   6