簡體   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) 

輸入列名(ieReports_to)和你想要過濾結果的列的值

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

output

    name manager
  0 Orid     John
  1 David    John

使用列表理解 -

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM