在多列上平均
我试图找到计算新列的平均值。
data['english_combined'] = data['english'] + data['intake_english'] + data['language test scores formatted']
因此,English_combined列是其他列的总和。我想根据输入哪些等级来命中均值,例如,只有“英语”和“ inktake_english”有一个等级,我想以这2的平均值。 3个测试结合在一起,
我确实尝试了这样的事情,没有
[np.mean(i,j,k) for i,j,k in zip(data['english'], data['intake_english'], data['language test scores formatted'])]
任何成功的建议?
I am trying to find calculate the mean for a new column.
data['english_combined'] = data['english'] + data['intake_english'] + data['language test scores formatted']
so the english_combined column is a the sum of the other columns. I want to take the mean based on what grades are entered, example if only 'English' and 'inktake_english' have a grade I want to take the mean of these 2. if all 3 test are taken I want to take the mean of the 3 tests combined
I did try something like this with no succes
[np.mean(i,j,k) for i,j,k in zip(data['english'], data['intake_english'], data['language test scores formatted'])]
any suggestions that would work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
df.mean(axis ='列')
执行您想要的。默认情况下,它忽略了NAN(也就是说,计算平均值时不会计算它们的总数)。一个简单的示例:
请注意,第2行的平均值6,而不是2。第1行类似。
对于您的情况,它就是类似的
df.mean(axis='columns')
does what you want. By default, it ignores NaNs (that is, it won't count them for the total when computing the average).A simple example:
Note how row 2 has 6 as its mean, not 2. Similar for row 1.
For your case, it would be something like