user2293224
user2293224

Reputation: 2220

Pandas: Replacing a row with another data frame

I have two data frames: df1

Data frame 1 :df1

and df2

Data frame 2: df2

Now I want to replace one of rows of df1 (highlighted in red colour) with all values of df2. I try with following codes but didn't give the desired result. Here is the code:

df1[df1['Category_2']=='Specified Functionality'].update(df2)

I also tried:

df1[df1['Category_2']=='Specified Functionality'] = df2

Could anyone guide me where I am making the mistake?

Upvotes: 2

Views: 253

Answers (1)

Nathaniel
Nathaniel

Reputation: 3290

You can insert the rows like this:

row = 13
df2 = df2.rename(columns = {'Functionality': 'Category_2')
df = pd.concat([df1[0:row], df2, df1[row+1:]]).reset_index(drop=True)

Upvotes: 1

Related Questions