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