pandas:将一个数据帧的行添加到另一个数据帧中?

3
我有两个具有相同列标题的数据框。
我正在遍历df1中的行,分割其中一个列,然后使用这些分割列创建多个行以添加到另一个数据框中。
for index, row in df1.iterrows():
    curr_awards = row['AWARD'].split(" ")
    for award in curr_awards:
        new_line = row
        new_line['AWARD'] = award.strip()
        #insert code here to add new_line to df2

如何使用Pandas方法向另一个数据框添加行?

1个回答

4

我懂了。

for index, row in df1.iterrows():
    curr_awards = row['AWARD'].split(" ")
    for award in curr_awards:
        new_line = row
        new_line['AWARD'] = award.strip()
        df2.loc[len(df2)] = new_line

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