简体   繁体   English

用两个数据框计算观察的数量

[英]Calculating the number of observations with two data frames

I have two dataframes (members and expeditions), there is a "members" column in expeditions that counts the number of members per expedition, I would like to find a way to check that there are as many members with this expedition_id in "members" as there are members in the "members" column of expeditions.我有两个数据框(成员和远征队),远征队中有一个“成员”列,用于计算每次远征队的成员数量,我想找到一种方法来检查“成员”中是否有尽可能多的成员具有此 expedition_id因为远征的“成员”栏中有成员。

Code: import pandas as pd members = pd.read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-09-22/members.csv") expeditions = pd.read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-09-22/expeditions.csv")代码:导入 pandas 作为 pd 成员 = pd.read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-09-22/members.csv") expeditions = pd.read_csv( “https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-09-22/expeditions.csv”)

I had started by doing this but it makes an error.我已经开始这样做了,但它出错了。

nbre_membres_expedition = members[["expedition_id", "member_id"]].grouby("expedition_id", as_index = False).count()
nbre_membres_expedition = members[["expedition_id", "member_id"]].groupby("expedition_id", as_index = False).count()

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

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