大 pandas :将行从一个数据框添加到另一数据框? [英] pandas: Add row from one data frame to another data frame?

查看:60
本文介绍了大 pandas :将行从一个数据框添加到另一数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个具有相同列标题的数据框.

I have two dataframes with identical column headers.

我要遍历df1中的行,拆分其中一列,然后使用这些拆分的列创建多个行以添加到另一个数据框中.

I am iterating over the rows in df1, splitting one of the columns, and then using those split columns to create multiple rows to add to the other dataframe.

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

What is the pandas method for adding a row to another data frame?

推荐答案

我知道了.

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

这篇关于大 pandas :将行从一个数据框添加到另一数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆