Python Resources
What is Python?
Python is a free, open-source programming language used for data analysis, scientific computing, and many other applications. Its readable syntax and extensive collection of packages make it a useful tool for students learning statistics and data science. Packages provide additional tools for tasks such as managing data, creating graphs, and fitting statistical models.
What can you do with Python?
- Manage data: Import files, handle missing values, combine datasets, and create new variables.
- Summarize data: Calculate descriptive statistics and create frequency tables.
- Visualize data: Create histograms, boxplots, scatterplots, and other graphs.
- Perform statistical analyses: Fit regression models, conduct hypothesis tests, and explore relationships among variables.
Get started with Python
You can run Python in a web browser or install it on your computer.
- Google Colab — use Python in your browser: Write and run Python code in online notebooks without installing software locally. A notebook combines code, results, and explanatory text.
- Try Jupyter — explore online notebook demonstrations: Try Jupyter tools through free browser-based demonstrations.
- Download Python — install Python on your computer: Find installers and instructions for your operating system.
If you are using Python for a course, follow your instructor’s recommendations for software and packages.
Basic programming examples
The following examples use fictional exam scores and Python’s built-in tools. No additional packages are required. Run the examples in order within the same Python session or notebook.
Create and display data
A list stores a collection of values. This example creates a list of five exam scores and displays it.
scores = [85, 92, 78, 88, 97]
print(scores)
The output shows the five scores: 85, 92, 78, 88, and 97.
Calculate summary statistics
Python’s statistics module includes functions for common descriptive statistics. The stdev function calculates the sample standard deviation.
import statistics print("Number of scores:", len(scores))
print("Mean:", statistics.mean(scores))
print("Median:", statistics.median(scores))
print("Sample standard deviation:",
round(statistics.stdev(scores), 2))
print("Minimum:", min(scores))
print("Maximum:", max(scores))
The mean and median are both 88. The sample standard deviation is approximately 7.18, and scores range from 78 to 97.
Select observations that meet a condition
A list comprehension creates a new list from existing values. This example selects scores of at least 90.
high_scores = [score for score in scores if score >= 90]
print("Scores of at least 90:", high_scores)
print("Number of scores of at least 90:", len(high_scores))
The selected scores are 92 and 97, so two scores meet the condition.
Learning resources
- Python Beginner’s Guide: Find starting points for learners with or without previous programming experience.
- Official Python Tutorial: Learn Python syntax, data structures, functions, and other language features. This tutorial is best suited to readers with some programming experience.
- pandas getting-started tutorials: Learn to import, organize, summarize, and combine tabular data.
- NumPy learning resources: Explore numerical computing with arrays and mathematical operations.
- Matplotlib tutorials: Learn to create and customize graphs.
- statsmodels documentation and examples: Explore statistical modeling, hypothesis testing, and model diagnostics.