File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
LeetCode SQL 50 Solution/1729. Find Followers Count Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ Here's an improved ` README.md ` with a ** Python (Pandas) solution** alongside the ** SQL solution** :
2+
3+ ``` md
14# 📊 Find Followers Count - LeetCode 1729
25
36## 📌 Problem Statement
@@ -64,16 +67,51 @@ ORDER BY user_id;
6467
6568---
6669
70+ ## 🐍 Python (Pandas) Solution
71+
72+ ### ✅ ** Approach:**
73+ 1 . Use ` groupby("user_id") ` to count followers for each user.
74+ 2 . Use ` reset_index(name="followers_count") ` to format the result properly.
75+ 3 . Sort the result by ` user_id ` .
76+
77+ ``` python
78+ import pandas as pd
79+
80+ def find_followers_count (followers : pd.DataFrame) -> pd.DataFrame:
81+ result = (
82+ followers.groupby(" user_id" )[" follower_id" ]
83+ .count()
84+ .reset_index(name = " followers_count" )
85+ .sort_values(" user_id" )
86+ )
87+ return result
88+ ```
89+
90+ ---
91+
6792## 📁 File Structure
6893```
6994📂 Find-Followers-Count
7095│── 📜 README.md
7196│── 📜 solution.sql
97+ │── 📜 solution.py
7298│── 📜 test_cases.sql
99+ │── 📜 test_cases.csv
73100```
74101
75102---
76103
77104## 🔗 Useful Links
78105- 📖 [ LeetCode Problem] ( https://leetcode.com/problems/find-followers-count/ )
79106- 📝 [ MySQL COUNT Function] ( https://www.w3schools.com/sql/sql_count.asp )
107+ - 🐍 [ Pandas GroupBy] ( https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html )
108+ ```
109+
110+ ---
111+
112+ ### 🚀 **What's New in this Version?**
113+ ✅ **Added Python (Pandas) Solution**
114+ ✅ **Structured File Organization**
115+ ✅ **Includes Helpful Links for Learning**
116+
117+ Would you like any further enhancements? 🚀
You can’t perform that action at this time.
0 commit comments