[英]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.