Pivot Tables & Data Merge in Python with Pandas

🚀 Today’s Learning: Pivot Table & Data Merge in Python Working with data becomes powerful when you can both summarize and combine it effectively! 🔹 Pivot Table (using pandas) Pivot tables are powerful for summarizing large datasets into a structured format. They help in identifying patterns, trends, and comparisons across categories 💻 Example: import pandas as pd data = { 'Region': ['North', 'South', 'East', 'West'], 'Sales': [100, 150, 200, 130] } df = pd.DataFrame(data) pivot = pd.pivot_table(df, values='Sales', index='Region', aggfunc='sum') print(pivot) 📌 Output: Region East  200 North  100 South  150 West  130 🔹 Data Merge (Combining datasets) Data merging is used to combine datasets based on a common key, similar to SQL joins. This is very useful when working with multiple tables like customers, orders, and products. 💻 Example: df1 = pd.DataFrame({ 'ID': [1, 2, 3], 'Name': ['A', 'B', 'C'] }) df2 = pd.DataFrame({ 'ID': [1, 2, 3], 'Score': [90, 85, 88] }) merged = pd.merge(df1, df2, on='ID') print(merged) 📌 Output: ID Name Score 0  1  A   90 1  2  B   85 2  3  C   88 ✨ Pivot to analyze. Merge to integrate. Together, they transform raw data into actionable insights! #Python #Pandas #DataAnalytics #DataScience #Learning #PivotTable #DataMerge

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories