3

I have two dataframes with identical column headers.

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

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

1 Answer 1

4

I figured it out.

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.