使用pandas过滤数据帧

2024-10-01 04:48:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我的密码tried:I can 能够根据第一次输入进行分组,但需要过滤方面的帮助

需要对Jobgrade=2和Age=23的组进行分组

import pandas as pd
df=pd.read_csv(r'C:\Users\Nishank\Desktop\tests.csv')
input_list = [['Jobgrade','Age'],[2,23]]
cols=input_list[0]
rows=input_list[1]
dy = df.groupby(cols).first()
print(dy)

输入数据帧:

enter image description here

预期输出:

enter image description here


Tags: csvimport密码pandasdfinputageas