如何在Pandas中将所有列合并为一列?

3
我正在尝试使用pandas库将数据框的列合并为一列:
DF是表格:enter image description here
oneCol = []
colLength = len(finalDF)
for k in range(colLength):
    oneCol.append(DF[k])
combined = pd.DataFrame(oneCol)
combined

但输出结果是在此输入图片描述

我想要的只是一个单列的数据框。谢谢。


这也可以通过 pandas 的 stack() 函数来实现。请参阅 https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.stack.html#pandas.DataFrame.stack。 - Puneet7nov
1个回答

3
combined = pd.concat(oneCol, ignore_index=True)

太好了。谢谢你。 - Matt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接