How to Learn Python for data analytics (Step-By-Step) in 2023

Here is a step-by-step guide to learning Python for data analytics in 2023:

Here is a step-by-step guide to learning Python for data analytics in 2023:

  1. Start by learning the basic syntax and concepts of Python, such as variables, data types, loops, and control structures. Best to Join Vista Academy

  2. Next, familiarize yourself with the Python standard library, particularly the math, statistics, and date/time modules. These modules contain functions and methods that will be useful for data analytics tasks.

  3. After you have a solid foundation in Python, it’s time to start working with data. You’ll need to learn how to import, clean, and manipulate data using libraries like NumPy, Pandas, and Matplotlib.

  4. Once you’re comfortable with the basics of data manipulation, you can start learning more advanced techniques such as machine learning, data visualization, and data analysis. There are many online tutorials, courses, and resources available to help you learn these skills.

  5. As you learn, it’s important to practice your skills by working on real-world projects. This will help you apply what you’ve learned and give you a chance to demonstrate your knowledge to potential employers.

  6. Finally, consider getting certified in Python for data analytics. This can help you stand out in the job market and demonstrate your expertise to employer


Introduction to Python for data Analytics

Python is a high-level, interpreted programming language. It was first released in 1991 and has become one of the most popular programming languages in the world, with a large and active community of users and developers. Python is known for its simplicity, readability, and flexibility, as well as its support for object-oriented, imperative, functional, and procedural programming styles. Python is used for a wide range of applications, including web development, scientific computing, data analysis, machine learning, and artificial intelligence.


The new oil is data. This statement demonstrates how data capture, storage, and analysis are at the heart of every modern IT system. It doesn’t matter if you’re making a business choice, forecasting the weather, investigating protein structures in biology, or creating a marketing strategy. All of these scenarios call for a multidisciplinary approach that includes the use of mathematical models, statistics, graphs, databases, and, of course, the commercial or scientific rationale that underpins the data analysis. As a result, we need a programming language that can handle all of these different data science requirements. Python stands out as one of these languages since it comes with a plethora of libraries and built-in capabilities that make it simple to meet the demands of data research.


Python has libraries

Python contains a number of libraries that contain a significant number of mathematical functions and analytical tools.

The following libraries will be used in this course:

Pandas – This library is used to do structured data operations such as importing CSV files, creating dataframes, and preparing data.

Numpy is a library for mathematicians. There’s an N-dimensional array object, linear algebra, and the Fourier transform, among other things.

Matplotlib is a library that allows you to visualise data.

SciPy is a Python library that includes linear algebra modules.

Comment in Python

Comments are text blocks that live in your code but are disregarded by the Python interpreter when it runs it. You can use comments to describe the code so that you and other developers can understand what it does and why it’s written the way it is. Simply add a hash mark (#) before your remark text to make a comment in Python: Example : 
# This is a comment on its own line

Variable in python

In Python, variables are names tied to a particular object. They keep a reference to the memory address where an item is stored, often known as a pointer. Once a variable has been assigned to an object, the object can be accessed by using the variable name. You must declare your variables advance. The syntax is as follows:
num = 100 #num is of type int
str = "Chaitanya" #str is of type string

Identifiers - Variable name

The term “identifier” refers to the name of a variable. When naming variables in Python, there are a few guidelines to follow. 1. The variable’s name must always begin with a letter or an underscore ( ). For example, the variables _str, str, num, and _num are all allowed names. 2. The variable’s name must not begin with a number. 9num, for instance, is not an acceptable variable name. 3. Variable names cannot contain special characters like percent, $, or #; they must only contain alphanumeric characters and underscore (A to Z, a to z, 0-9, or ). 4. In Python, variable names are case sensitive, therefore num and NUM are two separate variables.

Python Variable Example

num = 100
str = "VistaAcademy"
practice in below 

What is the meaning of a Python keyword?

A reserved term in Python is one that you can’t use as the name of a variable, class, function, or anything else. These keywords have a specific meaning and are used in the Python programming language for specific purposes.

Here is a list of the Python keywords. Enter any keyword to get more help.

False            def           if                          raise
None             del          import                   return
True              elif          in                              try
and              else          is                         while
as                 except    lambda                 with
assert           finally    nonlocal                  yield
break           for            not
class           from            or
continue     global                                  pass

Example of Variable

Example of Python keyword
num = 10
while num>5:
num -= 1

Python data Type

  1. Integer: Integers are whole numbers. They can be positive, negative, or zero. For example: 2, -5, 0.
  2. Float: Floats are numbers with a decimal point. They can be positive, negative, or zero. For example: 3.14, -2.5, 0.0.
  3. String: Strings are sequences of characters. They can be defined using single quotes (‘) or double quotes (“). For example: ‘hello’, “world”, “123”.
  4. Boolean: Booleans represent one of two values: True or False. For example: True, False.
  5. List: Lists are collections of items that are ordered and changeable. They can contain elements of any data type. Lists are defined using square brackets ([]). For example: [1, 2, 3], [‘apple’, ‘banana’, ‘cherry’], [True, False, True].
  6. Tuple: Tuples are similar to lists, but they are immutable (i.e., they cannot be changed). They are defined using parentheses (()). For example: (1, 2, 3), (‘apple’, ‘banana’, ‘cherry’), (True, False, True).
  7. Dictionary: Dictionaries are collections of items that are unordered and changeable. They are organized using key-value pairs. Dictionaries are defined using curly braces ({}). For example: {‘name’: ‘John’, ‘age’: 30}, {1: ‘apple’, 2: ‘banana’, 3: ‘cherry’}, {True: ‘yes’, False: ‘no’}.
  8. Set: Sets are collections of items that are unordered and unchangeable. Sets are defined using curly braces ({}). For example: {1, 2, 3}, {‘apple’, ‘banana’, ‘cherry’}, {True, False}.
I hope this helps! Let me know if you have any questions.

Numeric Types

Integer –

In Python 3, there is no upper bound on the integer number which means we can have the value as large as our system memory allow
x = 20

#display x:

#display the data type of x:


It is automatically inferred based on the value we are assigning to a variable. For example here fnum is a float data type.
# float number
fnum = 34.45
print("Data Type of variable fnum is", type(fnum))

Complex Number

x = 1j
#display x:

#display the data type of x:

Python Data Type – String

String is a sequence of characters in Python. The data type of String in Python is called “str”. Strings in Python are either enclosed with single quotes or double quotes. # Python program to print strings and type
s = "This is a String"
s2 = 'This is also a String'

# displaying string s and its type

print(s2) print(type(s2))

Boolean Values

In programming you often need to know if an expression is True or False. You can evaluate any expression in Python, and get one of two answers, True or False. Example 1
print(10 > 9)

print(10 == 9)

print(10 < 9)
Example 2

a = 200
b = 330

if b > a:
print("b is greater than a")
print("b is not greater than a")

Operator in Python

+ addition

x = 5
y = 3

print(x + y)


x = 5
y = 3

print(x - y)


x = 6
y = 3

print(x * y)


x = 12
y = 7

print(x / y)


x = 5
y = 2

print(x % y)


x = 2
y = 5

#shows remender of division

print(x ** y) #same as 2*2*2*2*2

//Floor division

x = 15
y = 2

print(x // y)

#the floor division // rounds the result down to the nearest whole number

Python Assignment Operators

x +=

x = 5

x += 3

#answer will be 8


x = 5

x -= 3

#answer will be 2


x = 5

x *= 3

#answer will be 15 


x = 5

x /= 3



x = 5


#shows remainder 2


x = 5

#shows result in integer 2


x = 5

x **= 3

#mutiply 5*5*5


x = 5

x &= 3


Python Logical Operator


Logical AND: True if both the operands are true.


Logical OR: True if either of the operands is true x or y

# Print a and b is False
print(a and b)

# Print a or b is True
print(a or b)

# Print not a is False
print(not a)


Data Structure in Python

Data structures in Python are ways of organizing and storing data in a structured and efficient manner. They provide different ways to store, access, and manipulate data based on their properties and intended use cases. Python offers several built-in data structures, each with its own advantages and use cases. Some common data structures in Python are:

Python Data Type – List

List is similar to tuple in that it is an ordered collection of elements. However, unlike tuple, list is a changeable data type, which means it can be altered.
# list of integers
lis1 = [1, 2, 3, 4, 5]
# prints entire list
# list of strings
lis2 = ["Apple", "Orange", "Banana"]
# loop through list elements
for x in lis2:
print (x)
# List of mixed type elements
lis3 = [20, "Chaitanya", 15, "BeginnersBook"]
Print a specific element in list
indexes start with zero
print("Element at index 3 is:",lis3[3])

Python Data Type – Tuple

In Python, a tuple is an unchanging data type, which means it cannot be modified. It’s a list of elements that are separated by commas and enclosed in round brackets.

t1 = (1, 2, 3, 4, 5)
# prints entire tuple

# tuple of strings

t2 = ("hi", "hello", "bye")
# loop through tuple elements
for s in t2:
print (s)
# tuple of mixed type elements
t3 = (2, "Lucy", 45, "Steve")
Print a specific element
indexes start with zero

Python data type Dictionary

In Python, a dictionary is a collection of keys and values. It is an unordered and changeable data type, and works like an associative array in other programming languages. Here is an example of how you can create a dictionary in Python:
my_dict = {'name': 'John', 'age': 30, 'city': 'New York'}
{'name': 'John', 'age': 30, 'city': 'New York'}

 name = my_dict['name']
John You can also add, remove, and modify the elements in a dictionary:
my_dict['age'] = 25
{'name': 'John', 'age': 25, 'city': 'New York'}

 my_dict[‘phone’] = ‘555-555-5555’
{'name': 'John', 'age': 25, 'city': 'New York', 'phone': '555-555-5555'}
del my_dict['phone']
{'name': 'John', 'age': 25, 'city': 'New York'}


  • Sets are unordered collections of unique items.
  • They do not allow duplicate values.
  • Useful for checking membership and performing set operations (union, intersection, etc.).
  • Defined using curly braces: my_set = {1, 2, 3}
Sets are useful when you want to store a collection of items without any duplicates and quickly check for membership or perform set operations like union, intersection, and difference. Sets are defined using curly braces {} or the set() constructor. Here’s an example of using sets in Python:
Creating a Set:
You can create a set using curly braces {} or the set() constructor. Sets automatically remove duplicate elements, so only unique elements are stored.  
# Creating a set using curly braces
my_set = {1, 2, 3, 4, 4, 5}
print(my_set)  # Output: {1, 2, 3, 4, 5}

# Creating a set using the set() constructor
another_set = set([3, 4, 5, 6, 6])
print(another_set)  # Output: {3, 4, 5, 6}
Adding Elements to a Set:
my_set = {1, 2, 3, 4, 5}
print(my_set)  # Output: {1, 2, 3, 4, 5, 6}

Removing Elements from a Set:

You can remove an element from a set using the remove() method. If the element doesn’t exist in the set, it will raise a KeyError
my_set = {1, 2, 3, 4, 5}
print(my_set)  # Output: {1, 2, 3, 5}

Checking Membership in a Set:

my_set = {1, 2, 3, 4, 5}
print(3 in my_set)  # Output: True
print(6 in my_set)  # Output: False

Set Operations:

set_a = {1, 2, 3, 4, 5}
set_b = {4, 5, 6, 7, 8}

# Union of two sets
union = set_a | set_b
print(union)  # Output: {1, 2, 3, 4, 5, 6, 7, 8}

# Intersection of two sets
intersection = set_a & set_b
print(intersection)  # Output: {4, 5}

# Difference between two sets
difference = set_a - set_b
print(difference)  # Output: {1, 2, 3}

# Symmetric difference (elements in either set, but not both)
symmetric_diff = set_a ^ set_b
print(symmetric_diff)  # Output: {1, 2, 3, 6, 7, 8}

if statement in python

In Python, an if statement is used to execute a block of code only if a certain condition is true. Here is the general form of an if statement in Python: if condition: # code to be executed Here is an example of an if statement in Python:
x = 10
if x > 5:
print("x is greater than 5")
In this example, the condition is x > 5. If the condition is true (in this case, it is), then the code inside the if block will be executed. In this case, the code inside the if block is print(“x is greater than 5”), which will print the string “x is greater than 5” to the console. You can also include an else clause in an if statement to specify a block of code that should be executed if the condition is false:
x = 3
if x > 5:
print("x is greater than 5")
print("x is not greater than 5")
n this example, the condition is x > 5, which is false. Therefore, the code inside the else block will be executed, which will print the string “x is not greater than 5” to the console. You can also use the elif keyword to specify additional conditions that should be checked if the initial if condition is false. For example
x = 3
if x > 5:
print("x is greater than 5")
elif x == 5:
print("x is equal to 5")
print("x is less than 5")
In this example, the initial condition is x > 5, which is false. The second condition, x == 5, is also false. Therefore, the code inside the else block will be executed, which will print the string "x is less than 5" to the console.

Loops in python

Loops are used to execute a block of code repeatedly for a certain number of times or until a certain condition is met. There are two types of loops in Python: for loops and while loops. Here is an example of a for loop that iterates over a range of numbers and prints each one to the console:
for i in range(10):
This will output the numbers 0 through 9. Here is an example of a while loop that continues to execute as long as a certain condition is true:
x = 0
while x < 10:
x += 1
This will output the numbers 0 through 9, just like the for loop above. Both for loops and while loops can be controlled using the break and continue statements. The break statement will exit the loop completely, while the continue statement will skip the rest of the current iteration and move on to the next one. I hope this helps! Let me know if you have any questions.

While Loop in python

A while loop in Python allows you to repeat a block of code as long as a certain condition is True. Here is the general syntax: while condition: code block The code block will be executed repeatedly as long as the condition is True. When the condition becomes False, the loop will terminate and control will be passed to the next line of code after the loop. Here is an example of a simple while loop that counts down from 5 and prints the count at each iteration:
count = 5
while count > 0:
count -= 1
This will output the following: 5 4 3 2 1 It is important to include a way to modify the condition within the loop, or else the loop will run forever (this is known as an infinite loop). In the example above, the count variable is decremented by 1 each time the loop runs, so eventually count will become 0 and the condition will be False, terminating the loop. You can also use the break statement to terminate a while loop early, before the condition becomes False.
count = 5
while True:
count -= 1
if count == 0:
  This loop will run the same as the previous example, but it uses an infinite loop and the break statement to achieve the same result.

function in python

Step 1: Defining a Function

In Python, a function is a block of code that performs a specific task and can be reused throughout your program. To define a function, you use the def keyword followed by the function name and a pair of parentheses. Here’s an example:    
 >def greet(name):
print(f"Hello, {name}!")
In this example, we’ve defined a function called greet that takes one parameter name.

Step 2: Function Parameters

Parameters are the inputs that a function receives. You can pass values (arguments) to a function when you call it. In the above example, name is a parameter.

Step 3: Function Body

The indented block of code under the def statement is the function body. This is where you write the code that performs the desired task. In our greet function, the body contains a single line that prints a greeting.

Step 4: Calling a Function

To use a function, you call it by using its name followed by parentheses. You can pass values (arguments) to the function if it expects any. Here’s how you call the greet function:
This will output: Hello, Alice!

Step 5: Return Statement (Optional)

Functions can also return values back to the caller using the return statement. Here’s an example:
def add(a, b):
    return a + b
In this example, the add function takes two parameters (a and b) and returns their sum.

Step 6: Function Call and Return Value

When you call a function that uses the return statement, you can capture the returned value in a variable:
result = add(5, 3)
print(result)  # This will print 8

Step 7: Default Parameters (Optional)

You can provide default values for function parameters. These values will be used if the caller doesn’t provide a value for that parameter:
def power(base, exponent=2):
    return base ** exponent

example of function in python


def add(x, y):
    return x + y

def subtract(x, y):
    return x – y

def multiply(x, y):
    return x * y

def divide(x, y):
    if y != 0:
        return x / y
        return “Cannot divide by zero”

print(“Select operation:”)
print(“1. Add”)
print(“2. Subtract”)
print(“3. Multiply”)
print(“4. Divide”)

choice = input(“Enter choice (1/2/3/4): “)

num1 = float(input(“Enter first number: “))
num2 = float(input(“Enter second number: “))

if choice == ‘1’:
    print(“Result:”, add(num1, num2))
elif choice == ‘2’:
    print(“Result:”, subtract(num1, num2))
elif choice == ‘3’:
    print(“Result:”, multiply(num1, num2))
elif choice == ‘4’:
    print(“Result:”, divide(num1, num2))
    print(“Invalid Input”)

To-Do List Program:

tasks = []
def add_task(task):
print("Task added:", task)

def remove_task(task):
if task in tasks:
print("Task removed:", task)
print("Task not found")

def display_tasks():
for index, task in enumerate(tasks, start=1):
print(f"{index}. {task}")

while True:
print("Select operation:")
print("1. Add Task")
print("2. Remove Task")
print("3. Display Tasks")
print("4. Quit")

choice = input("Enter choice (1/2/3/4): ")

if choice == '1':
task = input("Enter task: ")
elif choice == '2':
task = input("Enter task to remove: ")
elif choice == '3':
elif choice == '4':
print("Invalid Input")
Function with Default Argument:
def power(x, exponent=2):
    return x ** exponent

result = power(5)  # Uses default exponent (2)
result = power(3, 4)  # Custom exponent (4)
Scroll to Top
Data Analytics course in Dehradun Uttarakhand