【发布时间】:2021-08-16 14:55:13
【问题描述】:
我目前正在尝试使用 pandas 将来自两个不同数据框的列表合并在一起。我试图让 df1 中的每个单元格合并 df2 中的所有单元格。例如,我有以下两个数据框:
>>> df1
0 [This, is, a, sentence]
1 [this, is, another, sentence]
>>> df2
0 [this, is, also, a, sentence]
1 [this, too, is, a, sentence]
2 [this, is, very, different]
3 [another, sentence, is, this]
4 [not, much, of, anything]
我正在尝试将 df1 中的两个单元格与 df2 中的单元格合并,以提供以下输出:
>>> df_merged
0 [this, is, also, a, sentence, This, is, a, sentence]
1 [this, too, is, a, sentence, This, is, a, sentence]
2 [this, is, very, different, This, is, a, sentence]
3 [another, sentence, is, this, This, is, a, sentence]
4 [not, much, of, anything, This, is, a, sentence]
>>> df2_merged
0 [this, is, also, a, sentence, This, is, another, sentence]
1 [this, too, is, a, sentence, This, is, another, sentence]
2 [this, is, very, different, This, is, another, sentence]
3 [another, sentence, is, this, This, is, another, sentence]
4 [not, much, of, anything, This, is, another, sentence]
关于如何实现这一目标的任何想法?它们不一定需要拆分为不同的数据帧,它们可以位于同一数据帧的不同列中等
【问题讨论】: