简体   繁体   English

如何添加过滤器以便我可以对向经理报告的员工分组? 请指导我。 也让我知道下面的代码是否正确

[英]How to add filters so that I can group employees reporting to manager ?? Please guide me. Also let me know if the below code is correct or not

import requests
import pandas as pd
import io

"""reading url""" 
"""Creating the dataframe"""

urlData=requests.get(http://demo.rahierp.com/desk#List/Employee/List).content

df = pd.read_csv(io.StrigIO(urlData.decode('utf-8')))

 """Print the dataframe"""

 df

 """applying groupby() function to"""

"""group the data on reports_to"""

 gk = df.groupby('Reports To')

 gk


for Reports To,reports_to_df in gk:

print(Reports To)

print(reports_to_df) 

put column name (ieReports_to )and the value of column on which you want filter result输入列名(ieReports_to)和你想要过滤结果的列的值

df.loc[lambda df: df.Reports_to == 'John']

output output

    name manager
  0 Orid     John
  1 David    John

using list comprehension -使用列表理解 -

print(df.loc[df['manager']=='LMN'])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 请在以下python代码中让我知道问题 - Please let me know the problem in the following python code 谁能告诉我这条线在我的 python 代码中做了什么: - can anyone please let me know what does this line do in my python CODE: 我对镶木地板文件和 python 完全陌生,谁能告诉我如何读取 pyspark 中带有标题的镶木地板文件 - I am completely new to parquet files and python, Can anyone please let me know how to read parquet file with headers in pyspark 请纠正我。 我写的代码在笔记本里 - Correct me please . The code I wrote was in the notebook 请为我解释以下代码行。 即使用数据框的 2 列创建熊猫系列 - Please explain the following line of code for me. i.e pandas series creation using 2 columns of a dataframe 有人可以指导我如何在类中重用一个函数吗? - Can someone please guide me on how to reuse a function in a class? 下面的代码运行,但是永远不会为我显示按钮。 我只想要一个简单的按钮说退出 - The code below runs but will never display a button for me. I just want a simple button that says quit 有人可以用正确的方法指导我在以下代码中进行迭代吗 - Can someone guide me with correct way to iterate in the following code 您能否让我知道在 selenium python 的浏览器中的网络选项卡中捕获除 200 以外的状态代码的代码吗? - Can you please let me know the code to capture the status codes other than 200 in network tab in browser in selenium python? (python)你能告诉我下面代码中有什么问题吗 - (python) Can you please tell me what is the problem in the code below
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM