Python中文
首页
教程
问答
标签
搜索
登录
注册
如何在pandas dataframe中使用groupby或pivot表查找平均值?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在使用工资.csv找到<a href="https://www.kaggle.com/kaggle/sf-salaries/data" rel="nofollow noreferrer">https://www.kaggle.com/kaggle/sf-salaries/data</a>的数据集 我试图找到500个以上的职位数据点。之后计算每个职位的平均工资总额。输出是打印前10个赚钱的职称。 <a href="https://i.stack.imgur.com/ait89.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ait89.png" alt="enter image description here"/></a></p> <p>我所做的</p> <pre><code>salaries = pd.read_csv('Salaries.csv') salaries = salaries.drop(["Id", "Notes", "Status", "Agency"], axis = 1) salaries = salaries.dropna() salaries.head() jobtitlelist = (salaries.JobTitle.value_counts()>500)[0:10] data_10jobtitle = salaries[salaries.JobTitle.isin(jobtitlelist.index)] avgsalary_10jobtitle = data_10jobtitle.groupby(by=data_10jobtitle.JobTitle).TotalPayBenefits.mean() print(avgsalary_10jobtitle) </code></pre> <p>我的输出是 <a href="https://i.stack.imgur.com/qsc7X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qsc7X.png" alt="enter image description here"/></a></p> <p>我在想,我错过了一些我找不到确切输出的小东西。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>你需要改变这条线</p> <pre><code>jobtitlelist = salaries.JobTitle.value_counts()[(salaries.JobTitle.value_counts()>500)][0:10] </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何为此数据帧创建散点图?
7 回答
如何为此编写Django模板
7 回答
如何为此表达式编写正则表达式?
1 回答
如何为步进电机选择合适的值?
7 回答
如何为每15分钟间隔的日期时间行(在新列中)添加标签?
7 回答
如何为每一列创建汇总表?
9 回答
如何为每一组groupbyPandas做滚动“得到假人”
1 回答
如何为每一行分别运行函数(python)?
3 回答
如何为每一行生成一个随机数?
5 回答
如何为每一轮将pytorch模型输出存储到numpy
10 回答
如何为每个.py-fi文件创建单独的zip文件
8 回答
如何为每个<li class=”“><a>找到最近的上述同级<li>?
3 回答
如何为每个CSV列生成特定的文件?
8 回答
如何为每个csv文件使用read_csv,即使它是空的?PythonPandas
8 回答
如何为每个CSV文件创建单独的Pandas数据帧并给它们起有意义的名称?
7 回答
如何为每个datetime和每个id创建一行?
5 回答
如何为每个Django型号选择赋予不同的颜色
7 回答
如何为每个Django模型实例安排一个周期性的芹菜任务?
7 回答
如何为每个Django视图设置一个装饰器?
7 回答
如何为每个for循环迭代分配变量
6 回答