'Fill DataFrame 1 from a summary DataFrame 2

So I'm asking a question about the group in a completely ignorant way.

I would like to be able to fill a pandas DataFrame "df1" (600 rows and 7 columns) from a pandas DataFrame "df2" summary of (20 rows 7 columns), where df1 contains all the rows of df2 but in much larger size.

My question is if there is a method to fill in df1 from df2. The columns are identical as shown in the following picture:

enter image description here

In short, it is a question of constructing the df1 from the summary df2.

Is this operation possible and feasible?

Do you have any ideas or the beginnings of a solution?

Thank you in advance for your thoughts.

Good day to everyone :)



Solution 1:[1]

df2.index = df2["Tag"]
df1.index = df1["Tag"]
del df1["Tag"]
del df2["Tag"]
df2 = df2.apply(lambda x: df1.loc[x.index].values.tolist())[0]
pd.DataFrame(df2.tolist(),df2.index)

a fast implementation way then, you can set tag column:

df2["Tag"] = df2.index
df1["Tag"] = df1.index

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MoRe