```html
``` Skip to contentAfter completing this lesson, you will be able to:
Python has become the most widely used programming language for Data Analytics, Data Science, Artificial Intelligence, Machine Learning, Automation, and Scientific Computing. Its simple syntax, extensive library ecosystem, and strong community support make it the preferred choice for beginners and professionals alike.
Unlike spreadsheet software, Python can process millions of records, automate repetitive tasks, connect to databases, analyze large datasets, and create professional visualizations. Modern Data Analysts use Python to clean data, perform statistical analysis, build predictive models, and automate reporting.
In this lesson, you will learn Python fundamentals that every Data Analyst should know before exploring powerful libraries such as NumPy, Pandas, and Matplotlib.
Python has become the industry standard for data analysis because it combines simplicity with powerful analytical capabilities.
Organizations across finance, healthcare, retail, manufacturing, education, marketing, and government use Python to solve data-driven problems.
Some major advantages of Python include:
Python is used throughout the data analytics workflow.
The official Python distribution can be downloaded from the Python Software Foundation website.
After installation, verify the installation using the following command.
python --version
You should see the installed Python version displayed in the terminal or command prompt.
Python code can be written using different development environments.
| Tool | Purpose |
|---|---|
| Jupyter Notebook | Interactive Data Analysis |
| Visual Studio Code | General Python Development |
| PyCharm | Professional Python IDE |
| Anaconda | Data Science Distribution |
| Google Colab | Cloud-Based Python Notebook |
Jupyter Notebook is an interactive programming environment widely used by Data Analysts and Data Scientists.
Unlike traditional code editors, Jupyter allows users to combine code, text, equations, charts, and outputs within a single notebook.
Advantages of Jupyter Notebook include:
The traditional first Python program displays a simple message.
print("Hello, World!")
The print() function displays output on the screen.
Python uses indentation instead of braces to define blocks of code.
Example:
if 10 > 5:
print("Ten is greater than five")
Proper indentation is mandatory in Python.
Variables store information that can be used later in the program.
name = "Rahul" age = 25 salary = 65000
Variables can store text, numbers, dates, lists, and many other types of information.
Good Examples:
customer_name total_sales average_salary
Poor Examples:
a x temp1
Python supports several built-in data types.
| Data Type | Example |
|---|---|
| Integer (int) | 100 |
| Float | 15.75 |
| String (str) | “Python” |
| Boolean (bool) | True |
| List | [10,20,30] |
| Tuple | (10,20,30) |
| Dictionary | {“Name”:”Rahul”} |
| Set | {1,2,3} |
The type() function returns the data type of a variable.
age = 25 print(type(age))
Output:
<class 'int'>
Operators perform calculations and comparisons.
| Operator | Meaning |
|---|---|
| + | Addition |
| – | Subtraction |
| * | Multiplication |
| / | Division |
| // | Floor Division |
| % | Modulus |
| ** | Exponent |
| Operator | Description |
|---|---|
| == | Equal To |
| != | Not Equal To |
| > | Greater Than |
| < | Less Than |
| >= | Greater Than or Equal To |
| <= | Less Than or Equal To |
| Operator | Purpose |
|---|---|
| and | Returns True if both conditions are true. |
| or | Returns True if at least one condition is true. |
| not | Reverses a Boolean value. |
x = 10 x += 5 x -= 2 x *= 4
Assignment operators update variable values efficiently.
The input() function allows users to enter values.
name = input("Enter your name: ")
print("Welcome", name)
User interaction is useful when creating data-driven applications.
The print() function displays information.
sales = 45000
print("Monthly Sales:", sales)
You can also format output using f-strings.
sales = 45000
print(f"Monthly Sales = {sales}")
Comments improve code readability and help explain program logic.
# Calculate total sales
""" This program calculates monthly revenue """
A retail company wants to calculate monthly revenue.
product_price = 1200
quantity_sold = 350
total_revenue = product_price * quantity_sold
print("Monthly Revenue =", total_revenue)
This simple Python program performs a calculation that forms the basis for many business analytics tasks. As datasets grow larger, Python libraries such as NumPy and Pandas automate these calculations across millions of records.
Continue to Part 2, where you will learn NumPy, Pandas, DataFrames, Series, reading CSV and Excel files, data cleaning, and real-world data manipulation techniques used by professional Data Analysts.
NumPy (Numerical Python) is one of the most important Python libraries for Data Analytics, Scientific Computing, and Machine Learning. It provides high-performance multidimensional arrays along with mathematical functions that perform calculations much faster than traditional Python lists.
Many popular Python libraries, including Pandas, Scikit-learn, and TensorFlow, are built on top of NumPy.
NumPy is designed for efficient numerical computation.
Major advantages include:
Import NumPy using the standard alias np.
import numpy as np numbers = np.array([10, 20, 30, 40, 50]) print(numbers)
The output is a NumPy array that supports efficient mathematical operations.
Unlike Python lists, NumPy performs calculations on all elements simultaneously.
import numpy as np numbers = np.array([10,20,30,40]) print(numbers + 5) print(numbers * 2) print(numbers / 2)
This feature is called vectorization, making NumPy significantly faster than traditional loops.
NumPy includes many built-in statistical functions.
| Function | Purpose |
|---|---|
| mean() | Average |
| median() | Median |
| std() | Standard Deviation |
| sum() | Total |
| min() | Minimum Value |
| max() | Maximum Value |
Example
import numpy as np sales = np.array([1200,1500,1800,1700]) print(sales.mean()) print(sales.std()) print(sales.max())
Pandas is the most widely used Python library for Data Analysis and Data Manipulation. It provides easy-to-use data structures that simplify working with structured datasets.
Pandas is built on top of NumPy and offers powerful tools for reading, cleaning, transforming, filtering, and analyzing data.
Most Data Analysts spend a large portion of their time using Pandas.
import pandas as pd
The standard alias for Pandas is pd.
A Series is a one-dimensional labeled array.
import pandas as pd sales = pd.Series([1200,1500,1800,1700]) print(sales)
A Series behaves similarly to a single column in a spreadsheet.
A DataFrame is a two-dimensional table consisting of rows and columns.
It is the primary data structure used in Data Analytics.
import pandas as pd
data = {
"Name":["Rahul","Priya","Amit"],
"Sales":[25000,32000,29000]
}
df = pd.DataFrame(data)
print(df)
CSV files are commonly used for storing business data.
import pandas as pd
df = pd.read_csv("sales.csv")
This command imports the CSV file into a DataFrame.
Pandas can also import Microsoft Excel files.
import pandas as pd
df = pd.read_excel("sales.xlsx")
This enables analysts to work directly with Excel datasets.
Pandas provides several methods for quickly inspecting datasets.
df.head()
df.tail()
df.info()
df.describe()
These commands help analysts understand the structure and quality of the data.
Retrieve a single column.
df["Sales"]
Select multiple columns.
df[["Name","Sales"]]
Filtering returns only rows that satisfy a condition.
df[df["Sales"] > 30000]
This displays employees whose sales exceed 30,000.
Sort data in ascending or descending order.
df.sort_values("Sales")
df.sort_values("Sales", ascending=False)
Create calculated columns using existing data.
df["Bonus"] = df["Sales"] * 0.10
This calculates a 10% bonus for each employee.
Real-world datasets often contain missing information.
df.isnull().sum()
df.dropna()
df.fillna(0)
Cleaning missing values improves analysis accuracy.
The groupby() function summarizes data by categories.
df.groupby("Department")["Sales"].sum()
Business Example:
Calculate total sales generated by each department.
Business data is often stored in multiple tables.
Pandas allows datasets to be merged using common columns.
merged = pd.merge(customers,
orders,
on="Customer_ID")
This combines customer information with order details.
A retail company receives daily sales data in CSV format.
The Data Analyst performs the following tasks using Pandas:
Using only a few lines of Python code, the analyst transforms thousands of raw records into a structured dataset ready for reporting and dashboard creation.
Continue to Part 3, where you will learn Matplotlib, Line Charts, Bar Charts, Histograms, Scatter Plots, integrating NumPy, Pandas, and Matplotlib, business applications, case studies, FAQs, lesson summary, and key takeaways.
Matplotlib is one of the most popular Python libraries for data visualization. It allows Data Analysts to transform raw numerical data into meaningful charts and graphs that make trends, patterns, and comparisons easier to understand.
Matplotlib is widely used in Data Analytics, Data Science, Machine Learning, Finance, Marketing, Healthcare, and Business Intelligence. Many advanced visualization libraries, including Seaborn, are built on top of Matplotlib.
Data visualization helps stakeholders understand business performance quickly.
Matplotlib provides:
Import the visualization module using the standard alias.
import matplotlib.pyplot as plt
The pyplot module contains most charting functions used by Data Analysts.
Line charts display trends over time.
import matplotlib.pyplot as plt
months = ["Jan","Feb","Mar","Apr","May"]
sales = [12000,15000,17000,16000,19000]
plt.plot(months, sales)
plt.title("Monthly Sales")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.show()
Business Example: Monitor monthly sales growth.
Bar charts compare values across categories.
products = ["Laptop","Mobile","Printer","Monitor"]
sales = [450,620,180,320]
plt.bar(products, sales)
plt.title("Product Sales")
plt.show()
Business Example: Compare product sales performance.
Histograms display the distribution of numerical values.
import numpy as np
marks = np.random.normal(70,10,100)
plt.hist(marks)
plt.title("Exam Score Distribution")
plt.show()
Business Example: Analyze customer ages or employee salaries.
Scatter plots help identify relationships between two numerical variables.
advertising = [5,10,15,20,25]
sales = [50,65,78,90,110]
plt.scatter(advertising, sales)
plt.xlabel("Advertising Budget")
plt.ylabel("Sales")
plt.show()
Business Example: Study the relationship between advertising expenditure and sales revenue.
Matplotlib allows extensive customization.
You can modify:
Example:
plt.plot(months,
sales,
color="green",
marker="o",
linewidth=2)
plt.grid(True)
Pandas DataFrames work directly with Matplotlib.
import pandas as pd
df = pd.read_csv("sales.csv")
df.groupby("Month")["Revenue"].sum().plot()
plt.show()
This combines data analysis and visualization in a few lines of code.
Python libraries work together to solve real business problems.
| Library | Purpose |
|---|---|
| NumPy | Numerical Computing |
| Pandas | Data Cleaning and Analysis |
| Matplotlib | Data Visualization |
A typical analytics workflow is:
A nationwide retail company receives daily transaction data from hundreds of stores.
The Data Analyst develops a Python workflow that:
This automated workflow reduces manual reporting time from several hours to just a few minutes while improving reporting accuracy.
Python has become an essential programming language for Data Analytics because of its simplicity, flexibility, and extensive ecosystem of libraries. NumPy enables efficient numerical computation, Pandas simplifies data manipulation and cleaning, and Matplotlib provides powerful visualization capabilities. Together, these libraries allow Data Analysts to import, prepare, analyze, and visualize data efficiently, forming the foundation for advanced analytics, Machine Learning, and Artificial Intelligence projects.
Python is easy to learn, open source, supports powerful analytical libraries, and integrates with databases, Business Intelligence tools, and Machine Learning frameworks.
NumPy provides fast numerical operations, multidimensional arrays, and statistical functions that support scientific computing and Data Analytics.
Pandas is used for importing, cleaning, transforming, filtering, merging, and analyzing structured datasets.
Matplotlib is a Python visualization library used to create line charts, bar charts, histograms, scatter plots, and many other graphical representations of data.
Python can automate many analytical tasks that are difficult or time-consuming in Excel. However, Excel remains valuable for quick analysis and reporting, while Python is better suited for automation, large datasets, and advanced analytics.
In the next lesson, you will learn Introduction to Machine Learning and explore supervised learning, unsupervised learning, model training, prediction, and how Machine Learning extends the capabilities of Data Analytics.