繁体   English   中英

pandas:从一个数据帧添加行到另一个数据帧?

[英]pandas: Add row from one data frame to another data frame?

我有两个具有相同列标题的数据帧。

我正在迭代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方法是什么?

我想到了。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM