Menu

Python Basics for Data Analysis

Python Basics for Data Analysis

You do not need to master all of Python to analyze data. This topic covers only the basics you will use most, including variables, conditions, loops, and functions.

a. Variables and Data Types

A variable is a name that stores a value. You create one by writing the name, an equals sign, and the value. Python figures out the type on its own.

name = "Asha"
age = 25
price = 99.5
is_member = True

The four most common data types are strings for text, integers for whole numbers, floats for decimals, and booleans for True or False. In data analysis, you will see all four types in almost every dataset.

You can check a variable's type using the type() function. Knowing the type matters because it decides what you can do with the value. You cannot add a number to a piece of text, for example.

b. Operators and Conditional Statements

Operators let you perform actions on values. Arithmetic operators like +, -, *, and / do math. Comparison operators like >, <, and == compare two values and return True or False.

Conditional statements let your code make decisions. You use if, elif, and else to run different code based on a condition. This is the same idea behind filtering data later.

score = 72
if score >= 90:
print("Excellent")
elif score >= 50:
print("Pass")
else:
print("Needs work")

c. Loops in Python

A loop repeats a block of code many times. The for loop goes through each item in a collection one by one. The while loop keeps running as long as a condition stays true.

Loops are useful when you need to process many values. For example, you can go through a list of sales numbers and add them up. This saves you from writing the same line again and again.

sales = [120, 250, 180]
total = 0
for amount in sales:
total = total + amount
print(total)

d. Functions and Their Use in Analysis

A function is a reusable block of code that does one job. You define it once and call it whenever you need it. This keeps your code short and easy to read.

def calculate_average(numbers):
return sum(numbers) / len(numbers)
print(calculate_average([10, 20, 30]))

Functions are very helpful in data analysis. If you clean data the same way in many places, you can put the steps in one function. Later, if the logic changes, you only need to fix it in one spot.

Python also comes with built-in functions like len(), sum(), min(), and max(). You will use these often when summarizing data.


Data Analysis with Python Handbook

WR

Wesline Rinisha



Learn via Video Course

Data Analysis and Processing with Python using Pandas - Data Science Course Logo

Data Analysis and Processing with Python using Pandas - Data Science Course

5 hrs



Get in Touch For Details