File tree 6 files changed +111
-0
lines changed
0185.Department Top Three Salaries
0196.Delete Duplicate Emails
6 files changed +111
-0
lines changed Original file line number Diff line number Diff line change @@ -139,4 +139,30 @@ FROM
139
139
WHERE rk <= 3 ;
140
140
```
141
141
142
+ ### ** Pandas**
143
+
144
+ ``` python
145
+ import pandas as pd
146
+
147
+
148
+ def top_three_salaries (
149
+ employee : pd.DataFrame, department : pd.DataFrame
150
+ ) -> pd.DataFrame:
151
+ salary_cutoff = (
152
+ employee.drop_duplicates([" salary" , " departmentId" ])
153
+ .groupby(" departmentId" )[" salary" ]
154
+ .nlargest(3 )
155
+ .groupby(" departmentId" )
156
+ .min()
157
+ )
158
+ employee[" Department" ] = department.set_index(" id" )[" name" ][
159
+ employee[" departmentId" ]
160
+ ].values
161
+ employee[" cutoff" ] = salary_cutoff[employee[" departmentId" ]].values
162
+ return employee[employee[" salary" ] >= employee[" cutoff" ]].rename(
163
+ columns = {" name" : " Employee" , " salary" : " Salary" }
164
+ )[[" Department" , " Employee" , " Salary" ]]
165
+
166
+ ```
167
+
142
168
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -135,4 +135,30 @@ FROM
135
135
WHERE rk <= 3 ;
136
136
```
137
137
138
+ ### ** Pandas**
139
+
140
+ ``` python
141
+ import pandas as pd
142
+
143
+
144
+ def top_three_salaries (
145
+ employee : pd.DataFrame, department : pd.DataFrame
146
+ ) -> pd.DataFrame:
147
+ salary_cutoff = (
148
+ employee.drop_duplicates([" salary" , " departmentId" ])
149
+ .groupby(" departmentId" )[" salary" ]
150
+ .nlargest(3 )
151
+ .groupby(" departmentId" )
152
+ .min()
153
+ )
154
+ employee[" Department" ] = department.set_index(" id" )[" name" ][
155
+ employee[" departmentId" ]
156
+ ].values
157
+ employee[" cutoff" ] = salary_cutoff[employee[" departmentId" ]].values
158
+ return employee[employee[" salary" ] >= employee[" cutoff" ]].rename(
159
+ columns = {" name" : " Employee" , " salary" : " Salary" }
160
+ )[[" Department" , " Employee" , " Salary" ]]
161
+
162
+ ```
163
+
138
164
<!-- tabs:end -->
Original file line number Diff line number Diff line change
1
+ import pandas as pd
2
+
3
+
4
+ def top_three_salaries (
5
+ employee : pd .DataFrame , department : pd .DataFrame
6
+ ) -> pd .DataFrame :
7
+ salary_cutoff = (
8
+ employee .drop_duplicates (["salary" , "departmentId" ])
9
+ .groupby ("departmentId" )["salary" ]
10
+ .nlargest (3 )
11
+ .groupby ("departmentId" )
12
+ .min ()
13
+ )
14
+ employee ["Department" ] = department .set_index ("id" )["name" ][
15
+ employee ["departmentId" ]
16
+ ].values
17
+ employee ["cutoff" ] = salary_cutoff [employee ["departmentId" ]].values
18
+ return employee [employee ["salary" ] >= employee ["cutoff" ]].rename (
19
+ columns = {"name" : "Employee" , "salary" : "Salary" }
20
+ )[["Department" , "Employee" , "Salary" ]]
Original file line number Diff line number Diff line change 97
97
p1 .id < p2 .id ;
98
98
```
99
99
100
+ ### ** Pandas**
101
+
102
+ ``` python
103
+ import pandas as pd
104
+
105
+
106
+ # Modify Person in place
107
+ def delete_duplicate_emails (person : pd.DataFrame) -> None :
108
+ # Sort the rows based on id (Ascending order)
109
+ person.sort_values(by = " id" , ascending = True , inplace = True )
110
+ # Drop the duplicates based on email.
111
+ person.drop_duplicates(subset = " email" , keep = " first" , inplace = True )
112
+
113
+ ```
114
+
100
115
<!-- tabs:end -->
Original file line number Diff line number Diff line change 93
93
p1 .id < p2 .id ;
94
94
```
95
95
96
+ ### ** Pandas**
97
+
98
+ ``` python
99
+ import pandas as pd
100
+
101
+
102
+ # Modify Person in place
103
+ def delete_duplicate_emails (person : pd.DataFrame) -> None :
104
+ # Sort the rows based on id (Ascending order)
105
+ person.sort_values(by = " id" , ascending = True , inplace = True )
106
+ # Drop the duplicates based on email.
107
+ person.drop_duplicates(subset = " email" , keep = " first" , inplace = True )
108
+
109
+ ```
110
+
96
111
<!-- tabs:end -->
Original file line number Diff line number Diff line change
1
+ import pandas as pd
2
+
3
+
4
+ # Modify Person in place
5
+ def delete_duplicate_emails (person : pd .DataFrame ) -> None :
6
+ # Sort the rows based on id (Ascending order)
7
+ person .sort_values (by = "id" , ascending = True , inplace = True )
8
+ # Drop the duplicates based on email.
9
+ person .drop_duplicates (subset = "email" , keep = "first" , inplace = True )
You can’t perform that action at this time.
0 commit comments