【问题标题】:search for an specific character in each line in one column [closed]在每一列的每一行中搜索特定字符[关闭]
【发布时间】:2020-12-22 14:41:50
【问题描述】:

我有一个这样的数据集:

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

【问题讨论】:

    标签: python pandas group-by


    【解决方案1】:

    我会做以下事情:

    #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 的评论 - 一般来说,分享示例数据集并描述您已经尝试过的内容会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-15
      • 2015-01-03
      • 2011-09-02
      • 1970-01-01
      • 2013-05-30
      相关资源
      最近更新 更多