我有一个这样的数据名:
#Load the required libraries
import pandas as pd
import matplotlib.pyplot as plt
#Create data_set
data_set = {'id': [1,
1,
1,
1,
1,
2,
2,
2,
2,
2,
3,
3,
3,
3,
3,
],
'Salary': [16,
16,
16,
16,
16,
42,
42,
42,
42,
42,
28,
28,
28,
28,
28,
],
'Reference_id': [1,
2,
3,
4,
5,
1,
2,
3,
4,
5,
1,
2,
3,
4,
5,
],
'Reference_Salary': [10,
20,
30,
40,
50,
10,
20,
30,
40,
50,
10,
20,
30,
40,
50,
],
'Expenditure': [100,
210,
320,
430,
540,
90,
200,
310,
420,
530,
80,
190,
300,
410,
520,
],
'Leaves': [ 17.5,
45. ,
72.5,
100. ,
127.5,
7.5,
35. ,
62.5,
90. ,
117.5,
2.5,
25. ,
52.5,
80. ,
107.5,
],
}
#Convert to dataframe
df = pd.DataFrame(data_set)
print("\n df = \n",df)
数据框如下所示:
这里,‘id=1’出现了5次,需要与‘Reference_Salary=10到50’进行比较,后者由其对应的‘Reference_id=1到5’来标记.
薪资差异以及整行应该从最小到最大显示.
同样的逻辑也适用于df的其他id.
我希望在数据帧中看到结果:
有没有人能告诉我如何用Python语言来完成这个任务?