Python 在一列中的每行中搜索特定字符

Python 在一列中的每行中搜索特定字符,python,pandas,group-by,Python,Pandas,Group By,我有这样一个数据集: 我想搜索包含“工程师”的主题字段。然后 计算每个工程领域的平均论文数,并显示此表和总论文数 领域内的作者信息。有人能帮我吗。我会做以下事情: #use the Pandas library import pandas as pd #read in the data data = pd.read_csv('file.csv') #read in the data #add a new column that is 1 if 'Engineer' appears in th

我有这样一个数据集:

我想搜索包含“工程师”的主题字段。然后 计算每个工程领域的平均论文数,并显示此表和总论文数
领域内的作者信息。有人能帮我吗。

我会做以下事情:

#use the Pandas library
import pandas as pd

#read in the data
data = pd.read_csv('file.csv') #read in the data
#add a new column that is 1 if 'Engineer' appears in the Subject Field, else 0
data['isEngineeringRelated']=data['Subject Field'].map(lambda x: 1 if 'Engineer' in x else 0)
#filter for engineering rows
engineering_data = data[data['isEngineeringRelated']==1]
#groupby the engineering fields and count the average number of papers of authors in that field
print(engineering_data.groupby('Subject Field')['Number of Papers'].mean())
我不确定您所说的“在字段信息中显示此表的作者总数”的确切含义,但也许这段代码可以帮助您开始

顺便说一句,我同意Celius的评论——一般来说,分享一个示例数据集并描述您已经尝试过的内容会有所帮助