简体   繁体   English

如果该行出现在第二个 dataframe 中,您如何将两个数据框组合在两个值上并添加一个包含 boolean 的额外列?

[英]How do you combine two data frames on two values and add an extra column containing a boolean for if the row appeared in the second dataframe?

I have two csv files, one with an ID, a year and some other stats and then I have another csv file with just the name and year.我有两个 csv 文件,一个带有 ID、年份和其他一些统计信息,然后我有另一个 csv 文件,其中只有名称和年份。 The first is just a collection of all users, years and the corresponding stats and the other is for winners of an award and the year that they won it.第一个是所有用户、年份和相应统计数据的集合,另一个是针对某个奖项的获奖者和他们赢得该奖项的年份。 I'm trying to combine the two and have the result as an extra column in the first data set showing a boolean value for if they won an award that year or not.我正在尝试将两者结合起来,并将结果作为第一个数据集中的额外列显示 boolean 值,如果他们在那一年获得了奖项。

eg [embiijo01,2018-19,...] and [embiijo01,2018-19] would turn into [embiijo01,2018-19,...,1]例如 [embiijo01,2018-19,...] 和 [embiijo01,2018-19] 将变成 [embiijo01,2018-19,...,1]

pd.merge(csv_1, csv_2, on = 'ID/Name/User/identification of the person', how = 'left')

Should be able to just do simple if statement and append or add column for the boolean.应该能够只做简单的 if 语句和 append 或为 boolean 添加列。

https://towardsdatascience.com/why-and-how-to-use-merge-with-pandas-in-python-548600f7e738 https://towardsdatascience.com/why-and-how-to-use-merge-with-pandas-in-python-548600f7e738

暂无
暂无

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

相关问题 如何基于一个数据框中的一列和第二个数据框中的两列合并两个数据框 - How to merge two data frames based on one column in one data frame and two column in second dataframe 您如何为单独的 dataframe 中的每个值重复 dataframe 的每一行,然后将两者组合成一个 dataframe? - How do you repeat each row for a dataframe for each value in a seperate dataframe and then combine the two into a single dataframe? 如何将包含先前值的 dataframe 与包含当前值的数据帧结合起来? - How to combine a dataframe containing previous values ​with data frames containing current values? 比较两个数据帧并根据掩码值将新列添加到数据帧 - compare two data frames and add new column to dataframe based on mask values 如果两个数据框中都存在列及其值,如何合并两个数据框? - How do I merge two data frames if a column and it's values exist in both data frames? 合并两个数据框而无需公共列 - Combine two data frames without a common column 如何使用第二个 dataframe 的列名和第一个 dataframe 两列中的值匹配两个数据框 - How to match two data frames using columns' names of the second dataframe and the value in two columns of the first dataframe 我有两个数据框 df 和 df1 具有相同的 id 列,但两个数据框中的列名不同,我想在第二个 dataframe 中更新值 - I have a two data frames df and df1 have same id columns but different column names in both data frames and I want update values in second dataframe 如何从包含给定字符串的行开始切片两列熊猫数据帧? - How do I slice a two column pandas dataframe starting with a row containing a given string? 如何在熊猫中组合两个数据框? - How combine two data frames in pandas?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM