如何在Python中堆叠列

时间:2019-05-25 11:42:26

标签: python-3.x pandas

我要使用python在excel工作表中有两列和多行,我想堆叠数据(类似于我们在minitab中的操作方式)

这就是我的数据的样子

CmpTimestamp = []
for index,element in enumerate(1stColumn1stDataset):
    for idx,el in enumerate(1stColumn2ndDataset):
        if truncate(element*100)/100 == truncate(el/10)/100: 
            CmpTimestamp.append(truncate(element*100)/100)

我已经尝试过使用堆栈函数,但是发生的是数据存储在索引值中

CmpTimestamp

预期结果

Adults-------------------------------->Children

Did Not Purchase------------------>Did Not Purchase

Did Not Purchase------------------>Purchased

Did Not Purchase------------------->Did Not Purchase

Did Not Purchase------------------->Purchased

Did Not Purchase------------------>Did Not Purchase

Did Not Purchase------------------->Did Not Purchase

Did Not Purchase-------------------->Did Not Purchase

Did Not Purchase------------------->Purchased

Did Not Purchase------------------->Did Not Purchase

Did Not Purchase------------------->Did Not Purchase

Did Not Purchase------------------->Did Not Purchase

Did Not Purchase-------------------->Did Not Purchase

Purchased-------------------------->Did Not Purchase

Purchased-------------------------->Did Not Purchase

Purchased-------------------------->Did Not Purchase

Did Not Purchase-------------------->Did Not Purchase

Did Not Purchase-------------------->Did Not Purchase

Did Not Purchase--------------------->Did Not Purchase

Did Not Purchase-------------------->Did Not Purchase

1 个答案:

答案 0 :(得分:0)

df_adult = df[['Adults']].copy()

df_child = df[['Children']].copy()

df_final = df_adult.append(df_child,ignore_index=True)