与AVERAGEIF等效的Excel的Python列生成 [英] Python Column Generation with AVERAGEIF equivalent to Excel

查看:91
本文介绍了与AVERAGEIF等效的Excel的Python列生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把StackOverflow倒了,只是想不通这一点.我有一个具有唯一letter#组合的数据表,并尝试将这些值的平均值"放入第二个表中.基本上,我正在尝试生成下面的"AVG"列.

I've poured over StackOverflow and just cant figure this one out. I a data tables with unique letter# combinations, and im trying to get the "averageif" of those values into the second table. Basically, I am trying to generate the "AVG" column below.

Letter  Value      Unique   Avg
A1  7.97           A1       5.76
A1  3.56           A2       5.34 
A2  3.16           A3       1.53
A2  9.09           B1       4.55
A2  0.64           B2       5.43
A2  8.48           B3       6.76
A3  1.53
B1  4.55
B2  7.36
B2  3.81
B2  7.30
B2  4.39
B2  4.30
B3  4.61
B3  8.91

我已经使用pd.DataFrame将第一个数据集中的唯一值隔离为唯一值的DataFrame,但是我确实遇到了麻烦.我有所有代码可以从csv中提取此数据,生成唯一值,等等,但似乎并不相关.感谢您的任何建议,我只是无法通过这一步.

I've used pd.DataFrame to isolate the unique values in the first data set as a DataFrame of unique values, but I'm really having trouble. I have all the code to pull this data in from a csv, generate the unique values, etc but it doesnt seem relevant. Thanks for any advice, I just cant get passed this step.

最佳

推荐答案

好吧,您可以使用groupby做到这一点,如下所示:

Well, you can do that using groupby as follows:

df.groupby('Letter').mean()

这篇关于与AVERAGEIF等效的Excel的Python列生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆