简体   繁体   English

检查pandas数据帧中是否存在其他数据帧中的行,并根据它所属的数据帧分配点

[英]Check if a row in a pandas dataframe exists in other dataframes and assign points depending on which dataframes it also belongs to

In this question this problem is solved partially to check if a row in a dataframe exists in another one. 这个问题中,部分地解决了这个问题,以检查数据帧中的行是否存在于另一个中。

What I have is many dataframes df1, df2, df3, df4 etc. which are subsets of a larger dataframe df. 我所拥有的是许多数据帧df1,df2,df3,df4等,它们是较大数据帧df的子集。

Now, for each row in df, I want to create a new column "RATING", and I want to assign a value. 现在,对于df中的每一行,我想创建一个新列“RATING”,我想分配一个值。

For example if row1 in df is contained in df1 add 50 points, if it is also contained in df2 add another 30 points, in df3 add 40 points, in df4 subtract 10 points, etc. 例如,如果df中的row1包含在df1中,则添加50个点,如果它还包含在df2中,则添加另外30个点,在df3中添加40个点,在df4中减去10个点等。

row1 then will have a new column "RATING" with the total. 然后row1将有一个新列“RATING”与总数。 Then do the same for row2, etc. 然后为row2等做同样的事情。

How can I accomplish this? 我怎么能做到这一点?

Apply the exact methodology of the other question you are pointing at to get one additional boolean column per dataframe. 应用您指向的其他问题的确切方法,以便为每个数据帧获得一个额外的布尔列。 You will end up with n extra columns being Exist_in_df1, Exist_in_df2, ..., Exist_in_dfn 你最终将有n个额外的列是Exist_in_df1,Exist_in_df2,...,Exist_in_dfn

Now you have a simple boolean matrix to work with against which you can apply your simple rating logic 现在,您可以使用一个简单的布尔矩阵来应用简单的评级逻辑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM