pandas 如何在python panda中根据条件添加列

f45qwnt8  于 2022-12-02  发布在  Python
关注(0)|答案(1)|浏览(156)

I have two dataframes where i want to append two columns based on a condition.
I have the two following dataframes:

I want to add TS%_mean and TS%_SD to the other data if the year matches to the first DataFrame so that each player has their mean and standard deviation for that year.
I have tried to itterate through a loop and having some conditions for the addition of columns. Everything I have tried does not work as intended unfourtunately.

pnwntuvh

pnwntuvh1#

假设您有dfdf2,则可以使用merge

df.merge(df2, on = 'Year')

您可能还需要学习joins。虽然链接是基于SQL的,但您将学习连接表的基础知识,以便创建更复杂的连接。

相关问题