合并下一行中的值

2024-09-26 21:41:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试合并两个数据帧:

this are tables I am trying to merge

and this is the result I want to achieve

所以,我希望合并的值不在同一行上。你知道吗

当我尝试这样合并时:

pd.merge(a,b,how='inner', on=['date_install','device_os'])

它将值合并到一个原始值中。你知道吗

请建议如何解决


Tags: andtheto数据tablesisresultmerge
2条回答

您可以使用append()

df1.append(df2, ignore_index = True)

或者使用concat()

pd.concat([df,df1], ignore_index = True)

或使用merge()

df.merge(df1, how = 'outer')

引用自:https://stackoverflow.com/a/24391268/3748167(可能重复)

这里唯一的区别是先连接两个数据帧,然后应用其余的逻辑。你知道吗

def sjoin(x): return ';'.join(x[x.notnull()].astype(str)) pd.concat([a,b]).groupby(level=0, axis=1).apply(lambda x: x.apply(sjoin, axis=1))

相关问题 更多 >

    热门问题