Insert DataFrame in Dataframe based on a condition

Viewed 37

need a help to get empty dataframe updated and add a new dataframe inside it.

this is the scenario: I initiate empty datafram when loading the code :

enter image description here

I don't use index key, it has index name and there are duplicate index values (Rows) such as USA.

How do I update the table_1 column of the row( where index = USA and category = Home) and add a new Datafrme inside it.

I read a excel worksheet and I need to add it in the empty dataframe

I can do it with the below code but the both rows (USA/Home and USA/Car) are updated.

df.update(pd.DataFrame({table_1: dataframe2}, index=[USA]))

enter image description here

The above code is good when there is no condition. I need to do the same with a condition.

I have tried with the code below but it is not adding the new df into the cell instead code is adding 'nan enter image description here enter image description here

0 Answers
Related