2016-08-19 89 views
0

我有两个具有相同列标题的数据帧。熊猫:从一个数据框添加行到另一个数据框?

我遍历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方法是什么?

回答

2

我想通了。

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 
相关问题