<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Timothy Njeru</title>
    <description>The latest articles on DEV Community by Timothy Njeru (@timothy_njeru_5bbb87f705f).</description>
    <link>https://dev.to/timothy_njeru_5bbb87f705f</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3879014%2Fe624e05a-1890-4ae8-85f5-92b59ddd6ba8.png</url>
      <title>DEV Community: Timothy Njeru</title>
      <link>https://dev.to/timothy_njeru_5bbb87f705f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/timothy_njeru_5bbb87f705f"/>
    <language>en</language>
    <item>
      <title>Introduction to Python for Data Analytics</title>
      <dc:creator>Timothy Njeru</dc:creator>
      <pubDate>Wed, 29 Apr 2026 08:05:58 +0000</pubDate>
      <link>https://dev.to/timothy_njeru_5bbb87f705f/introduction-to-python-for-data-analytics-2eka</link>
      <guid>https://dev.to/timothy_njeru_5bbb87f705f/introduction-to-python-for-data-analytics-2eka</guid>
      <description>&lt;p&gt;Introduction to Python for Data Analytics&lt;br&gt;
Every data journey has a starting point. Mine began with a single question: "How do people actually make sense of all this data?" The answer, I quickly discovered, is Python.&lt;br&gt;
I'm currently enrolled in the LuxDevHQ Intermediate Python Certification Course, and in this article I want to share what I've learned so far — not from a textbook perspective, but from the lens of someone actively going through the process. If you're just starting out with Python for data analytics, this article is for you.&lt;/p&gt;

&lt;p&gt;Step 1: Setting Up the Environment — Choosing Your Tools&lt;br&gt;
Before writing a single line of Python, I had to make a key decision: where do I actually write and run my code? This turned out to be more interesting than I expected, because there isn't just one answer.&lt;br&gt;
Here's every tool I installed and what I learned about each:&lt;br&gt;
🐍 Anaconda&lt;br&gt;
Anaconda is a Python distribution built specifically for data science. When you install Anaconda, you don't just get Python — you get a whole ecosystem: pre-installed libraries, a package manager called conda, and access to tools like Jupyter Notebook and Spyder, all in one go.&lt;/p&gt;

&lt;p&gt;Why I'd recommend it for beginners: You spend zero time fighting with installations. Everything just works.&lt;/p&gt;

&lt;p&gt;📓 Jupyter Notebook&lt;br&gt;
Jupyter Notebook is the tool I've come to love most. It lets you write Python code in cells — small blocks you can run independently — and see the output right below each cell. You can also mix code with text, images, and explanations, which makes it perfect for data analytics work and for documenting your learning.&lt;/p&gt;

&lt;h1&gt;
  
  
  Launch Jupyter Notebook from your terminal or Anaconda Navigator
&lt;/h1&gt;

&lt;p&gt;jupyter notebook&lt;br&gt;
It opens right in your browser and you're ready to go.&lt;br&gt;
💻 VS Code (Visual Studio Code)&lt;br&gt;
VS Code is a lightweight but powerful code editor from Microsoft. With the Python extension installed, it gives you features like syntax highlighting, code suggestions (IntelliSense), and an integrated terminal. It's great for writing longer Python scripts and building real projects.&lt;br&gt;
🔬 Spyder&lt;br&gt;
Spyder comes bundled with Anaconda and feels a lot like MATLAB or RStudio if you've used those before. It has a Variable Explorer panel that lets you inspect your variables in real time — incredibly useful when you're learning how Python stores and handles data.&lt;br&gt;
☁️ Google Colab&lt;br&gt;
Google Colab is a free, cloud-based Jupyter Notebook environment from Google. No installation needed — just a Google account and a browser. It also gives you free access to GPUs, which becomes important later when you get into machine learning.&lt;/p&gt;

&lt;p&gt;My take: I use Jupyter or Colab for exploratory work and learning, and VS Code when writing more structured scripts. Having all these tools installed means I can choose the right one for the task at hand.&lt;/p&gt;

&lt;p&gt;Step 2: Python Basics — Writing Your First Code&lt;br&gt;
With the environment set up, the real learning began. Python's syntax is clean and readable, which makes it genuinely beginner-friendly. Here's what I covered in the basics.&lt;br&gt;
The print() Function — Your First Output&lt;br&gt;
print() is the most fundamental function in Python. It outputs text or values to the screen. Every Python learner starts here.&lt;br&gt;
CODE&lt;br&gt;
print("Hello, World!")&lt;br&gt;
print("Welcome to Python for Data Analytics")&lt;br&gt;
Output:&lt;br&gt;
Hello, World!&lt;br&gt;
Welcome to Python for Data Analytics&lt;br&gt;
You can print numbers, the result of calculations, and even multiple items at once:&lt;br&gt;
CODE&lt;br&gt;
print("The answer is:", 42)&lt;br&gt;
print(10 + 5)                      # Prints 15&lt;br&gt;
print("Pi is roughly", 3.14159)&lt;br&gt;
The input() Function — Getting Data from the User&lt;br&gt;
While print() sends information out, input() brings information in. It pauses the program and waits for the user to type something.&lt;br&gt;
python&lt;br&gt;
name = input("What is your name? ")&lt;br&gt;
print("Hello,", name + "! Welcome to data analytics.")&lt;br&gt;
Example interaction:&lt;br&gt;
What is your name? Brian&lt;br&gt;
Hello, Brian! Welcome to data analytics.&lt;/p&gt;

&lt;p&gt;Important note: input() always returns a string, even if the user types a number. To use it as a number, you need to convert it:&lt;/p&gt;

&lt;p&gt;age = input("Enter your age: ")&lt;br&gt;
age = int(age)   # Convert string to integer&lt;br&gt;
print("In 10 years, you will be", age + 10)&lt;br&gt;
Combining print() and input() — A Simple Example&lt;br&gt;
Here's a small program that puts both functions together:&lt;/p&gt;

&lt;p&gt;print("=== Student Score Checker ===")&lt;br&gt;
student_name = input("Enter student name: ")&lt;br&gt;
score = float(input("Enter score: "))&lt;/p&gt;

&lt;p&gt;if score &amp;gt;= 50:&lt;br&gt;
    print(student_name, "passed with a score of", score)&lt;br&gt;
else:&lt;br&gt;
    print(student_name, "did not pass. Score:", score)&lt;/p&gt;

&lt;p&gt;Step 3: Data Types — How Python Classifies Data&lt;br&gt;
One of the first concepts that truly clicked for me was data types. In analytics, data comes in many forms — names, numbers, dates, true/false flags — and Python has a specific type for each.&lt;br&gt;
Here are the core data types I've learned:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Integer (int) — Whole Numbers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;student_count = 45&lt;br&gt;
year = 2025&lt;br&gt;
temperature = -3&lt;/p&gt;

&lt;p&gt;print(type(student_count))   # &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Float (float) — Decimal Numbers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;gpa = 3.75&lt;br&gt;
price = 1299.99&lt;br&gt;
tax_rate = 0.16&lt;/p&gt;

&lt;p&gt;print(type(gpa))   # &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;String (str) — Text&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;name = "Alice Wanjiru"&lt;br&gt;
course = "Python for Data Analytics"&lt;br&gt;
city = 'Nairobi'&lt;/p&gt;

&lt;p&gt;print(type(name))   # &lt;/p&gt;

&lt;h1&gt;
  
  
  Useful string operations
&lt;/h1&gt;

&lt;p&gt;print(name.upper())                      # ALICE WANJIRU&lt;br&gt;
print(course.lower())                    # python for data analytics&lt;br&gt;
print(len(name))                         # 13 (number of characters)&lt;br&gt;
print(name.replace("Alice", "Bob"))      # Bob Wanjiru&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Boolean (bool) — True or False
Booleans are critical in data analytics for filtering and applying conditions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;is_enrolled = True&lt;br&gt;
has_paid = False&lt;br&gt;
passed_exam = True&lt;/p&gt;

&lt;p&gt;print(type(is_enrolled))            # &lt;br&gt;
print(is_enrolled and has_paid)     # False&lt;br&gt;
print(is_enrolled or has_paid)      # True&lt;br&gt;
Checking and Converting Data Types&lt;/p&gt;

&lt;p&gt;value = "2025"&lt;br&gt;
print(type(value))       # &lt;/p&gt;

&lt;p&gt;value = int(value)&lt;br&gt;
print(type(value))       # &lt;br&gt;
print(value + 5)         # 2030&lt;br&gt;
Data TypeExampleUse in Analyticsint45, 2025Counts, IDs, yearsfloat3.14, 99.9Prices, scores, ratesstr"Nairobi"Names, categories, labelsboolTrue, FalseFlags, conditions, filters&lt;/p&gt;

&lt;p&gt;Step 4: Data Structures — Organizing Collections of Data&lt;br&gt;
Individual values are useful, but real-world data always comes in collections. Python has four main data structures for this, and understanding them is foundational for data analytics.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;List — Ordered, Changeable Collection
Lists are the most commonly used data structure. They hold multiple items in order and can be changed after creation.
python# A list of student scores
scores = [85, 92, 78, 90, 88]&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print(scores[0])       # 85 — first item (index starts at 0)&lt;br&gt;
print(scores[-1])      # 88 — last item&lt;br&gt;
print(scores[1:4])     # [92, 78, 90] — slicing&lt;br&gt;
print(len(scores))     # 5&lt;/p&gt;

&lt;h1&gt;
  
  
  Modifying a list
&lt;/h1&gt;

&lt;p&gt;scores.append(95)      # Add to end&lt;br&gt;
scores.remove(78)      # Remove a value&lt;br&gt;
scores.sort()          # Sort ascending&lt;/p&gt;

&lt;p&gt;print(scores)          # [85, 88, 90, 92, 95]&lt;/p&gt;

&lt;p&gt;Why it matters for data: Think of a list like a single column in a spreadsheet — an ordered series of values you can loop through, filter, and analyze.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Tuple — Ordered, Unchangeable Collection
Tuples look like lists but use parentheses () and cannot be modified after creation. Use them for data that should stay fixed.
python# GPS coordinates — should never change
nairobi_location = (-1.2921, 36.8219)&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Student record that shouldn't be altered
&lt;/h1&gt;

&lt;p&gt;student = ("Brian Omondi", "D001", "Data Analytics")&lt;/p&gt;

&lt;p&gt;print(nairobi_location[0])   # -1.2921&lt;br&gt;
print(student[1])            # D001&lt;/p&gt;

&lt;h1&gt;
  
  
  Trying to change a tuple raises an error
&lt;/h1&gt;

&lt;h1&gt;
  
  
  student[0] = "Alice"   # ❌ TypeError
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Dictionary — Key-Value Pairs
Dictionaries store data as key: value pairs — like a real-world dictionary where you look up a word (key) to find its meaning (value). This is one of the most powerful structures for analytics.
python# A student record as a dictionary
student = {
"name": "Brian Omondi",
"age": 24,
"course": "Python for Data Analytics",
"score": 88.5,
"enrolled": True
}&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Accessing values
&lt;/h1&gt;

&lt;p&gt;print(student["name"])    # Brian Omondi&lt;br&gt;
print(student["score"])   # 88.5&lt;/p&gt;

&lt;h1&gt;
  
  
  Adding a new key
&lt;/h1&gt;

&lt;p&gt;student["grade"] = "A"&lt;/p&gt;

&lt;h1&gt;
  
  
  Updating a value
&lt;/h1&gt;

&lt;p&gt;student["score"] = 91.0&lt;/p&gt;

&lt;h1&gt;
  
  
  Looping through a dictionary
&lt;/h1&gt;

&lt;p&gt;for key, value in student.items():&lt;br&gt;
    print(f"{key}: {value}")&lt;br&gt;
Output:&lt;br&gt;
name: Brian Omondi&lt;br&gt;
age: 24&lt;br&gt;
course: Python for Data Analytics&lt;br&gt;
score: 91.0&lt;br&gt;
enrolled: True&lt;br&gt;
grade: A&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set — Unique, Unordered Collection
Sets automatically remove duplicate values — making them great for finding unique entries in a dataset.
python# Finding unique departments in a dataset
departments = {"Sales", "IT", "HR", "Sales", "IT", "Finance"}
print(departments)   # {'Finance', 'HR', 'IT', 'Sales'} — duplicates removed&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Set operations — useful for data comparisons
&lt;/h1&gt;

&lt;p&gt;students_math = {"Alice", "Bob", "Carol", "David"}&lt;br&gt;
students_python = {"Bob", "Carol", "Eve", "Frank"}&lt;/p&gt;

&lt;p&gt;print(students_math &amp;amp; students_python)   # {'Bob', 'Carol'} — in both&lt;br&gt;
print(students_math | students_python)   # all students across both classes&lt;br&gt;
print(students_math - students_python)   # {'Alice', 'David'} — math only&lt;/p&gt;

&lt;p&gt;Step 5: Operators — Performing Actions on Data&lt;br&gt;
Operators are the symbols and keywords Python uses to perform actions — calculations, comparisons, and logic. I think of them as the verbs of Python.&lt;br&gt;
Arithmetic Operators — Doing the Math&lt;/p&gt;

&lt;p&gt;a = 20&lt;br&gt;
b = 6&lt;/p&gt;

&lt;p&gt;print(a + b)    # 26  — Addition&lt;br&gt;
print(a - b)    # 14  — Subtraction&lt;br&gt;
print(a * b)    # 120 — Multiplication&lt;br&gt;
print(a / b)    # 3.3333... — Division (always returns float)&lt;br&gt;
print(a // b)   # 3   — Floor division (whole number only)&lt;br&gt;
print(a % b)    # 2   — Modulus (remainder)&lt;br&gt;
print(a ** b)   # 64000000 — Exponentiation&lt;br&gt;
A practical example:&lt;/p&gt;

&lt;p&gt;total_sales = 150000&lt;br&gt;
num_months = 6&lt;br&gt;
monthly_avg = total_sales / num_months&lt;br&gt;
print(f"Average monthly sales: KES {monthly_avg:,.2f}")&lt;/p&gt;

&lt;h1&gt;
  
  
  Average monthly sales: KES 25,000.00
&lt;/h1&gt;

&lt;p&gt;Comparison Operators — Asking Yes/No Questions&lt;br&gt;
Comparison operators return True or False and are essential for filtering data.&lt;/p&gt;

&lt;p&gt;score = 75&lt;/p&gt;

&lt;p&gt;print(score &amp;gt; 50)    # True  — Greater than&lt;br&gt;
print(score &amp;lt; 50)    # False — Less than&lt;br&gt;
print(score &amp;gt;= 75)   # True  — Greater than or equal to&lt;br&gt;
print(score &amp;lt;= 60)   # False — Less than or equal to&lt;br&gt;
print(score == 75)   # True  — Equal to&lt;br&gt;
print(score != 80)   # True  — Not equal to&lt;br&gt;
In context — filtering a list:&lt;/p&gt;

&lt;p&gt;scores = [72, 45, 88, 55, 91, 39]&lt;br&gt;
passing = [s for s in scores if s &amp;gt;= 50]&lt;br&gt;
print("Passing scores:", passing)   # [72, 88, 55, 91]&lt;br&gt;
Logical Operators — Combining Conditions&lt;/p&gt;

&lt;p&gt;age = 22&lt;br&gt;
gpa = 3.8&lt;/p&gt;

&lt;h1&gt;
  
  
  Both conditions must be true
&lt;/h1&gt;

&lt;p&gt;eligible = age &amp;gt;= 18 and gpa &amp;gt;= 3.5&lt;br&gt;
print("Eligible for scholarship:", eligible)   # True&lt;/p&gt;

&lt;h1&gt;
  
  
  Either condition can be true
&lt;/h1&gt;

&lt;p&gt;has_experience = False&lt;br&gt;
has_degree = True&lt;br&gt;
can_apply = has_experience or has_degree&lt;br&gt;
print("Can apply:", can_apply)   # True&lt;/p&gt;

&lt;h1&gt;
  
  
  Reverse a condition
&lt;/h1&gt;

&lt;p&gt;is_complete = False&lt;br&gt;
print("Still in progress:", not is_complete)   # True&lt;br&gt;
Assignment Operators — Shorthand Updates&lt;/p&gt;

&lt;p&gt;total = 0&lt;br&gt;
total += 500    # total = total + 500  → 500&lt;br&gt;
total += 300    # → 800&lt;br&gt;
total -= 100    # → 700&lt;br&gt;
total *= 2      # → 1400&lt;br&gt;
total //= 3     # → 466&lt;br&gt;
print(total)    # 466&lt;br&gt;
Putting It All Together — A Mini Analytics Example&lt;br&gt;
Here's a program that pulls together everything covered so far — data types, data structures, operators, print(), and input():&lt;/p&gt;

&lt;p&gt;print("=== Student Performance Report ===\n")&lt;/p&gt;

&lt;p&gt;students = [&lt;br&gt;
    {"name": "Alice", "score": 85},&lt;br&gt;
    {"name": "Bob", "score": 42},&lt;br&gt;
    {"name": "Carol", "score": 91},&lt;br&gt;
    {"name": "David", "score": 57},&lt;br&gt;
    {"name": "Eve", "score": 38},&lt;br&gt;
]&lt;/p&gt;

&lt;p&gt;total = 0&lt;br&gt;
passed = 0&lt;br&gt;
failed = 0&lt;/p&gt;

&lt;p&gt;for student in students:&lt;br&gt;
    total += student["score"]&lt;br&gt;
    if student["score"] &amp;gt;= 50:&lt;br&gt;
        passed += 1&lt;br&gt;
        status = "PASS ✅"&lt;br&gt;
    else:&lt;br&gt;
        failed += 1&lt;br&gt;
        status = "FAIL ❌"&lt;br&gt;
    print(f"{student['name']}: {student['score']} — {status}")&lt;/p&gt;

&lt;p&gt;average = total / len(students)&lt;br&gt;
pass_rate = (passed / len(students)) * 100&lt;/p&gt;

&lt;p&gt;print(f"\nTotal Students : {len(students)}")&lt;br&gt;
print(f"Average Score  : {average:.1f}")&lt;br&gt;
print(f"Pass Rate      : {pass_rate:.0f}%")&lt;br&gt;
print(f"Passed         : {passed}")&lt;br&gt;
print(f"Failed         : {failed}")&lt;br&gt;
Output:&lt;br&gt;
=== Student Performance Report ===&lt;/p&gt;

&lt;p&gt;Alice: 85 — PASS ✅&lt;br&gt;
Bob: 42 — FAIL ❌&lt;br&gt;
Carol: 91 — PASS ✅&lt;br&gt;
David: 57 — PASS ✅&lt;br&gt;
Eve: 38 — FAIL ❌&lt;/p&gt;

&lt;p&gt;Total Students : 5&lt;br&gt;
Average Score  : 62.6&lt;br&gt;
Pass Rate      : 60%&lt;br&gt;
Passed         : 3&lt;br&gt;
Failed         : 2&lt;br&gt;
This is essentially a mini data analytics pipeline — built entirely from the fundamentals we've covered.&lt;/p&gt;

&lt;p&gt;Key Takeaways So Far&lt;br&gt;
Looking back at the journey so far, a few things stand out:&lt;/p&gt;

&lt;p&gt;The environment matters. Having the right tools (Jupyter, VS Code, Colab, Spyder) makes learning smoother. Each tool has its own strengths.&lt;br&gt;
Basics are not boring. print(), input(), data types, and operators look simple — but they are the building blocks that everything else in data analytics rests on.&lt;br&gt;
Data structures are how you think about data. Lists, dictionaries, tuples, and sets aren't just Python features — they mirror how data is actually organized in the real world.&lt;br&gt;
Operators are everywhere. Every filter, calculation, and condition in data work uses operators under the hood.&lt;/p&gt;

&lt;p&gt;What Comes Next&lt;br&gt;
This is just the foundation. The road ahead includes:&lt;/p&gt;

&lt;p&gt;🔁 Control Flow — if/else, for loops, while loops for automating data processing&lt;br&gt;
🔧 Functions — Writing reusable blocks of code&lt;br&gt;
📦 Libraries — NumPy, Pandas, Matplotlib for real data analytics&lt;br&gt;
🗄️ Working with Files — Reading CSVs, Excel files, and JSON data&lt;br&gt;
📊 Data Visualization — Turning numbers into charts that tell stories&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
Python for data analytics isn't something you learn overnight — it's a skill you build layer by layer. Setting up the right tools, understanding how Python handles data through its types and structures, and learning how to operate on that data are the essential first layers.&lt;br&gt;
If you're starting out like I am, my biggest advice is: don't rush past the basics. The print() function, the humble list, the simple + operator — these things show up in every data script, every analytics notebook, and every machine learning model you'll ever build.&lt;br&gt;
The foundation is worth building well.&lt;/p&gt;

&lt;p&gt;Written as part of the LuxDevHQ Intermediate Python Certification Course.&lt;br&gt;
Follow along as I continue documenting my Python learning journey&lt;/p&gt;

</description>
      <category>python</category>
      <category>dataanalytics</category>
      <category>beginners</category>
      <category>datascience</category>
    </item>
  </channel>
</rss>
