python

Microsoft Excel has evolved far beyond basic spreadsheets. With the integration of Python in Excel, you can now harness the power of data science directly within your sheets—no need to switch apps!

In this post, we’ll demonstrate how to use Python in Excel to analyze data like:

RankCityStateEstimateCensus
1MumbaiMaharashtra2066765620411000
2DelhiDelhi1981400016787941
3BengaluruKarnataka122240008436675
4HyderabadTelangana99800006809970

🔍 What You’ll Learn

  • How to enable Python in Excel
  • Run basic Python code inside Excel
  • Calculate growth, percentage changes, and filter top cities

✅ Step 1: Enable Python in Excel

  1. Make sure you have Microsoft 365 (latest update) with Python in Excel Preview access.
  2. Click on any cell.
  3. Go to Formulas > Insert Python (or type =PY()).

🐍 Step 2: Write Python Code to Analyze Data

Assume your Excel table is in range A1:E5.

A. Calculate Population Growth

=PY("
import pandas as pd
df = workbook.sheets[0].range('A1:E5').to_pandas()
df['Growth'] = df['Estimate'] - df['Census']
df
")

B. Calculate Growth Percentage

=PY("
df['Growth %'] = (df['Growth'] / df['Census']) * 100
df
")

📊 Step 3: Sort by Growth %

excelCopyEdit=PY("
df_sorted = df.sort_values('Growth %', ascending=False)
df_sorted
")

🌟 Benefits of Python in Exce

  • Run pandas, matplotlib, and other popular Python libraries.
  • No need to install anything—runs in a secure Microsoft environment.
  • Combine Excel formulas + Python logic for advanced analysis.

🧠 Use Cases

  • Census growth comparisons
  • Predictive modeling on population
  • Data visualization (with Python graphs in future updates)

📌 Final Thoughts

With Python in Excel, you bridge the gap between spreadsheet simplicity and coding power. It’s a game-changer for analysts, researchers, and anyone who loves data!

Example:

Leave a Reply

Your email address will not be published. Required fields are marked *

Pinterest
Instagram