【发布时间】:2015-08-20 02:52:39
【问题描述】:
我尝试在 python 中反映一些复杂的 SQL 操作。从最初开始 - 要求是找出部门明智的获得最高薪水的 EMP_ID。 3个步骤:
分组(部门)
Max(Salary) - 每个部门
get(Emp_Id) - 每个部门
示例文件.csv
EMP_ID,NAME,AGE,ADDRESS,SAL,DEPT,LOC
1,ghk,3,PTBP,23,IME,bhmd
2,ghk,3,PTBP,23,IME,bhmd
3,ghk,3,PTBP,23,IME,bhmd
4,ghk,3,PTBP,23,IME-DATA,bhmd
5,ghk,3,PTBP,24,IME-DATA,bhmd
6,ghk,3,PTBP,23,IME,bhmd
7,ghk,3,PTBP,23,IME,bhmd
8,ghk,3,PTBP,29,IME-NA,bhmd
9,ghk,3,PTBP,23,IME,bhmd
10,ghk,3,PTBP,23,IME-NA,bhmd
我试过的代码:
import pandas as pd
from pandas import *
import numpy as np
from numpy import *
df=pd.read_csv("SAM_JOINS.csv",sep=",")
go=df["EMP_ID"]+df["AGE"]
df["SYSTEM_REVENUE"]=go
print (df)
b=df.groupby(["DEPT"],as_index=False)
gb1=b['DEPT'].agg({'Count':np.size})
print(gb1)
但未能明智地获得每个部门的 max(salary) 和 emp_id。 请在这方面帮助我,因为我是 python pandas 的新手。
【问题讨论】:
-
你能发布你想要的输出吗,你的解释不清楚你想要什么,例如
b.max()没有给你你想要的吗?
标签: python python-2.7 python-3.x numpy pandas