简体   繁体   中英

Computing Average In a Data Table in Python

Define the "data science experience" of a given person as the person's largest score among Regression, Classification, and Clustering. Compute the average data science experience among all MBA students.

The prompt here kind of confuses me when it says "the person's largest score among Regression, Classification, and Clustering." My approach was to add those 3 numbers together in a new column and find the mean of them along with every other MBA student.

Below was my attempt, but this returns the mean of every single MBA student in 1 row of the new column as opposed to the mean of that individual in their row.

def MbaAvgExp(row):
    if row['Program']=='MBA':
        return df['Regression']+df['Classification']+df['Clustering'].mean()
    else:
        return 0

df['MbaAvgExp']=df.apply(MbaAvgExp, axis=1)
df

What can I do to fix this, and if you think my understanding of the prompt is incorrect please explain what I'm missing.

数据表

我认为您应该更改if案例中的变量名称,并且您可能希望在该案例的 return 语句中添加一对括号。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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