Fundamentals 4 min read

Master Statistical Analysis in Excel & Python: Formulas and Pandas Code

This article demonstrates how to compute key statistical metrics such as sum, average, and standard deviation on Excel data using built‑in Excel formulas and a concise Python Pandas script, comparing both approaches and showing the resulting outputs.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Master Statistical Analysis in Excel & Python: Formulas and Pandas Code

Introduction

A fan asked how to implement statistical calculations on Excel data using Python. The author shares two practical solutions: one using Excel formulas and another using Python with Pandas.

Method 1: Excel Formulas

Enter the following formulas directly in Excel cells and fill down to calculate the required statistics.

=SUM(B2:GG2)/COUNTIF(B2:GG2,"<>0")<br/>=STDEVA(IF(B2:GG2=0,"",B2:GG2))

Method 2: Python with Pandas

Using Pandas simplifies the process. The script reads the Excel file, computes total, mean (excluding zeros), and standard deviation for each row, and prints the resulting DataFrame.

import pandas as pd
df = pd.read_excel('产品周需求.xlsx', usecols='A:GG', index_col=0)
df['total'] = df.iloc[:, :188].sum(axis=1)
df['mean'] = df.iloc[:, :188].apply(lambda x: x[x != 0].mean(), axis=1)
df['std'] = df.iloc[:, :188].apply(lambda x: x[x != 0].std(), axis=1)
print(df)

Conclusion

Both the Excel formulas and the Python Pandas script produce identical results, providing flexible options for performing statistical analysis on Excel datasets.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

statistical analysisExcel
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.