Back to insights

Python: The Language of Data Science

October 3, 2024Updated 9 min read

Python felt loose after years of C#, but that looseness exposed a different engineering workflow: shorten the distance between a question and evidence.

Structured application blocks unfolding into an exploratory Python notebook workflow

Part of the Python and Data Science for .NET Developers series

Phase Foundations, Part 2

Data Science Series — 6 articles
  1. When the First Visualization Answers the Wrong Question
  2. Data Science for .NET Developers
  3. Python: The Language of Data Science
  4. Exploring Nutritional Data Using K-means Clustering
  5. Exploratory Data Analysis with Python
  6. Learning Python in the Post-Copilot World

Filed under Pragmatic architecture and modernization

Topic cluster

Python and Data Science

Python, data analysis, visualization, and machine learning foundations from a .NET developer's perspective.

How Python Evolved to Dominate Data Science

Table of Contents

Python, created by Guido van Rossum in 1989, began as a hobby project aimed at improving on the limitations of the ABC programming language. Van Rossum wanted to create a language that was both simple to read and powerful enough to handle complex projects.

Today, Python has become one of the most popular languages in the world, particularly in the fields of data science and machine learning. I want to take you through Python’s history, its evolution, and why it is the go-to language for data scientists today.

The Origins of Python and the Problems It Solved

In the late 1980s, Guido van Rossum started working on Python with the goal of creating a versatile, high-level programming language that focused on readability and ease of use. Inspired by the simplicity of ABC but frustrated by its limitations, Van Rossum designed Python to be easy enough for beginners while still offering advanced features for experienced developers.

One of the major problems Python solved was making programming more accessible without sacrificing power. Its clear syntax reduced the complexity of writing code, allowing for rapid prototyping, especially in research and scientific environments.

Python was also intended to support multiple programming paradigms. This flexibility allowed developers to write code in a variety of styles, from object-oriented to functional programming. By combining simplicity with power, Python became an excellent tool for both teaching programming and developing complex systems.

Python’s Name and Lore

The name "Python" is a tribute to Van Rossum's love for the British comedy group Monty Python, reflecting his vision of the language as fun and approachable. Over the years, the Python community has embraced this playful spirit, resulting in a culture that celebrates humor, exemplified by Easter eggs like "The Zen of Python" which outlines the language’s philosophy in a witty manner.

Zen of Python

In order to see the Zen of Python, open a Python shell and type import this. You will be greeted with a set of guiding principles that capture the essence of Python’s design philosophy. The Zen of Python consists of 19 aphorisms, each representing a fundamental guideline for writing Pythonic code. Let's explore these principles in detail.

Beautiful is better than ugly

Python emphasizes clean, readable code. This principle is a call to write code that is aesthetically pleasing, easy to read, and not overly complex.

Explicit is better than implicit

Code should be straightforward and avoid hidden behaviors. Making the flow and logic of the code clear makes it easier for others to maintain and extend it.

Simple is better than complex

Simplicity is a core Python value. When faced with a problem, choose the simplest solution that works, as complexity can lead to errors and confusion.

Complex is better than complicated

While complexity is sometimes necessary, it should not be confused with over-complication. The Zen advises to keep complexity manageable and avoid convoluted solutions.

Flat is better than nested

Deeply nested structures are harder to understand and maintain. The principle advises against excessive use of hierarchies in code, favoring a flatter structure.

Sparse is better than dense

Code should not try to do too much in a single line. Dense, one-liner code may be impressive, but it is often hard to read and maintain.

Readability counts

Readable code is critical for collaboration. Python encourages well-documented, easy-to-read code over terse or cryptic implementations.

Special cases aren't special enough to break the rules

While some scenarios may tempt developers to break conventions, Pythonic code adheres to general best practices even in exceptional cases.

Although practicality beats purity

This principle tempers the previous one, acknowledging that there are cases where pragmatic solutions may override rigid adherence to rules.

Errors should never pass silently

Python favors raising exceptions rather than silently failing, making debugging easier and code behavior clearer.

Unless explicitly silenced

There are rare cases where it's acceptable to silence errors deliberately, as long as this choice is clearly documented.

In the face of ambiguity, refuse the temptation to guess

When code is ambiguous, it’s best to clarify rather than make assumptions. Guessing leads to fragile code that may break unexpectedly.

There should be one—and preferably only one—obvious way to do it

Python emphasizes having a clear and well-defined solution for most problems, minimizing ambiguity for developers.

Although that way may not be obvious at first unless you're Dutch

A humorous reference to Python's Dutch creator, Guido van Rossum, indicating that not all solutions are immediately clear but become so over time.

Now is better than never

This encourages timely execution in coding, avoiding procrastination.

Although never is often better than right now

Balancing the previous point, this aphorism advises patience and careful consideration over rushing a solution.

If the implementation is hard to explain, it's a bad idea

If you can't easily explain your code to a peer, it's probably too complex or convoluted. Simplicity and clarity should always be prioritized.

If the implementation is easy to explain, it may be a good idea

If your code is straightforward enough to be easily explained, it is likely a good solution. Simplicity and ease of understanding are strong indicators of well-designed code.

Namespaces are one honking great idea—let's do more of those!

Namespaces in Python help avoid conflicts and make the code more organized by grouping related functions and variables.

The Zen of Python is more than just a list of best practices; it is a philosophical foundation for Python programming. These principles shape how Python developers approach coding, encouraging simplicity, readability, and pragmatism. As you continue your journey with Python, keeping the Zen in mind will help you write cleaner, more maintainable code.

Historical Timeline: Key Milestones in Python's Development

Python’s journey from a niche language to the backbone of modern data science is rich with important milestones. Let's explore the timeline of Python's key developments through this interactive accordion.

1989-1991: The Creation and First Release

Python was created in December 1989 and officially released in February 1991 with version 0.9.0. The first version included features like exception handling and functions, laying the foundation for its future growth​.

2000: Python 2.0 and Unicode Support

Python 2.0 introduced list comprehensions, garbage collection, and most notably, Unicode support. This version made Python more suitable for modern computing needs, including handling non-ASCII text​.

2008: Python 3.0 and Breaking Compatibility

Python 3.0 was a major overhaul designed to fix inconsistencies in the language. It introduced changes such as the print() function and improved Unicode handling but was not backward compatible with Python 2, leading to a gradual transition​​.

2010s: Python Becomes the Language of Data Science

Python’s rise in data science can be attributed to its simplicity and the development of powerful libraries like NumPy and Pandas. By the 2010s, Python had become the preferred language for data scientists and researchers​​.

Getting Started with Python for C# Developers

As a C# developer, transitioning to Python will feel both familiar and different. While Python and C# are both object-oriented languages, Python’s dynamic typing and simpler syntax can make it easier to learn but may require some adjustments in coding style. Here are some quick comparisons and examples to help ease your transition.

  1. Variable Declaration

Variable declaration in C# requires specifying the data type, while Python does not.

C#
string message = "Hello, World!";
python
message = "Hello, World!"
  1. Conditional Statements

C# uses curly braces for block scopes, whereas Python uses indentation.

C#
if (x > 10) {
  Console.WriteLine("Greater than 10");
} else {
  Console.WriteLine("Less than or equal to 10");
}
python
if x > 10:
  print("Greater than 10")
else:
  print("Less than or equal to 10")
  1. Loops

The for loop in C# uses a different syntax for iteration, while Python provides more readable syntax.

C#
for (int i = 0; i < 5; i++) {
  Console.WriteLine(i);
}
python
for i in range(5):
  print(i)
  1. Defining Functions

C# functions require specifying return types, while Python functions are more flexible.

C#
int Add(int x, int y) {
  return x + y;
}
python
def add(x, y):
  return x + y
  1. Lists and Arrays

C# uses arrays with fixed sizes, while Python uses flexible lists.

C#
int[] numbers = {1, 2, 3, 4, 5};
python
numbers = [1, 2, 3, 4, 5]
  1. String Interpolation

C# uses $ for string interpolation, while Python uses f-strings.

C#
string name = "John";
Console.WriteLine(quot;Hello, {name}");
python
name = "John"
print(f"Hello, {name}")
  1. Exception Handling

Both languages use try-catch blocks, but Python's syntax is simpler.

C#
try {
  int result = 10 / 0;
} catch (DivideByZeroException ex) {
  Console.WriteLine("Cannot divide by zero");
}
python
try:
  result = 10 / 0
except ZeroDivisionError:
  print("Cannot divide by zero")
  1. Classes and Objects

C# requires explicit data types and access modifiers, while Python does not.

C#
public class Person {
  public string Name { get; set; }
  public int Age { get; set; }
}
python
class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age
  1. Inheritance

Both C# and Python support inheritance, but their syntax differs.

C#
public class Animal {
  public void Speak() {
    Console.WriteLine("Animal sound");
  }
}

public class Dog : Animal {
  public void Bark() {
    Console.WriteLine("Dog barks");
  }
}
python
class Animal:
  def speak(self):
    print("Animal sound")

class Dog(Animal):
  def bark(self):
    print("Dog barks")
  1. File Handling

Both C# and Python offer ways to read and write to files, but with different syntax.

C#
using (StreamReader sr = new StreamReader("file.txt")) {
  string line = sr.ReadToEnd();
  Console.WriteLine(line);
}
python
with open("file.txt", "r") as file:
  content = file.read()
  print(content)

Frequently Asked Questions (FAQ)

Why is Python so popular for data science?

Python’s simplicity, readability, and the vast ecosystem of data science libraries (like Pandas, NumPy, and scikit-learn) make it ideal for data analysis and machine learning.

How is Python different from C#?

Python is dynamically typed and emphasizes readability, while C# is statically typed and more verbose. Python is often preferred for rapid prototyping and data science.

What are the top libraries for data science in Python?

  • Pandas
  • NumPy
  • scikit-learn
  • Matplotlib
  • Seaborn
  • TensorFlow
  • PyTorch

Is Python good for beginners?

Yes! Python’s clear syntax and large community make it one of the best languages for beginners.

Summary Checklist

  • Python’s history and evolution explained
  • Key differences between Python and C# highlighted
  • Code samples use PrismJS markup
  • SEO and accessibility best practices followed
  • Table of Contents, FAQ, and Glossary included
  • Bootstrap 5 used for layout and navigation

Glossary of Terms

Data Science

Data science is an interdisciplinary field that uses scientific methods, algorithms, and systems to extract knowledge and insights from data. It combines statistics, computer science, and domain expertise to solve complex problems.

For more, see the Wikipedia article on Data Science.

Pandas

Pandas is a powerful open-source Python library for data manipulation and analysis, providing flexible data structures like DataFrames.

Learn more at Wikipedia: Pandas (software).

NumPy

NumPy is a fundamental package for scientific computing in Python, offering support for large, multi-dimensional arrays and matrices, along with mathematical functions.

See Wikipedia: NumPy for details.

PrismJS

PrismJS is a lightweight, extensible syntax highlighter used for displaying code samples in web pages. It supports many languages and plugins for line numbers and copy-to-clipboard.

More info: Wikipedia: Syntax highlighting.

Bootstrap 5

Bootstrap 5 is a popular open-source CSS framework for building responsive, mobile-first websites. It provides ready-to-use components and utilities for layout, navigation, and more.

See Wikipedia: Bootstrap (front-end framework).

Explore More Data Science Articles

Dive deeper into data science topics:

Explore More

Working through something similar?

If this maps to something you're working on, I'm glad to compare notes. Start with the system and the constraint that matters most.