From 51c22e754b9a928577b6d9192c3f2db4d81da1e0 Mon Sep 17 00:00:00 2001
From: Vichitravir Dwivedi <93407819+vichitravird@users.noreply.github.com>
Date: Sun, 15 Sep 2024 12:53:23 -0400
Subject: [PATCH] Update README.md
---
README.md | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index da02326..4327b09 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,25 @@
# Pandas4
-1 Problem 1 : Nth Highest Salary (https://leetcode.com/problems/nth-highest-salary/solution/)
+## 1 Problem 1 : Nth Highest Salary (https://leetcode.com/problems/nth-highest-salary/solution/)
+
+import pandas as pd
-2 Problem 2 : Second Highest Salary ( https://leetcode.com/problems/second-highest-salary/ )
+def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame:
+ df=employee['salary']
+ df=pd.DataFrame(df)
+ df=df.drop_duplicates()
+ df=df.sort_values('salary', ascending=False).head(N).tail(1)
+ return df[['salary']].rename(columns={'salary': f'getNthHighestSalary({N})'})
+## 2 Problem 2 : Second Highest Salary ( https://leetcode.com/problems/second-highest-salary/ )
+
+import pandas as pd
+def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame:
+ employee.drop_duplicates(subset=["salary"], inplace=True)
+ if employee.shape[0] < 2 :
+ return pd.DataFrame([[None]], columns=["SecondHighestSalary"])
+ employee.sort_values(by="salary", inplace=True, ascending=False)
+ employee = employee[["salary"]]
+ employee.rename(columns={"salary" : "SecondHighestSalary"}, inplace=True)
+ return employee.iloc[1:2]