Divide columns
Task:List in column the information of employees whose salaries are more than 8000 in each department (ranking from high to low).
Python
1 | import pandas as pd |
2 | file = "E:/txt/EMPLOYEE.txt" |
3 | data=pd.read_csv(file,sep='\t') |
4 | sales_df = data[data['DEPT']=='Sales'].sort_values('SALARY',ascending=False).reset_index(drop=True) |
5 | sales_df['FULLNAME'] = sales_df['NAME']+' '+sales_df['SURNAME'] |
6 | sales_df = sales_df[['FULLNAME','SALARY']] |
7 | hr_df = data[data['DEPT']=='HR'].sort_values('SALARY',ascending=False).reset_index(drop=True) |
8 | hr_df['FULLNAME'] = hr_df['NAME']+' '+hr_df['SURNAME'] |
9 | hr_df = hr_df[['FULLNAME','SALARY']] |
10 | data = pd.concat([sales_df,hr_df],axis=1) |
11 | print(data) |
When dividing column in pandas, the index should be reset, otherwise empty data will appear.
esProc
A | ||
1 | =connect("mysql") | Connect to database |
2 | =A1.query("select * from EMPLOYEE order by SALARY") | Sort by salary |
3 | =A2.select(DEPT=="Sales") | Sales department data |
4 | =A2.select(DEPT=="HR") | HR department data |
5 | =create(Sales,SALARY,HR,SALARY) | Create new table |
6 | =A5.paste(A3.(NAME+" "+SURNAME),A3.(SALARY),A4.(NAME+" "+SURNAME),A4.(SALARY)) | Fill in data |
esProc can easily create new table, fill in data and divide columns.