Here is a step-by-step guide to learning Python for data analytics in 2023:
Start by learning the basic syntax and concepts of Python, such as variables, data types, loops, and control structures. Best to Join Vista Academy
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.
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.
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.
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.
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”
print(num)
print(str)
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:
print(num)
num -= 1
Python data Type
- Integer: Integers are whole numbers. They can be positive, negative, or zero. For example: 2, -5, 0.
- Float: Floats are numbers with a decimal point. They can be positive, negative, or zero. For example: 3.14, -2.5, 0.0.
- String: Strings are sequences of characters. They can be defined using single quotes (‘) or double quotes (“). For example: ‘hello’, “world”, “123”.
- Boolean: Booleans represent one of two values: True or False. For example: True, False.
- 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].
- 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).
- 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’}.
- 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:
print(x)
#display the data type of x:
print(type(x))
Float
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(fnum)
print(“Data Type of variable fnum is”, type(fnum))
Complex Number
x = 1j
#display x:
print(x)
#display the data type of x:
print(type(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(s)
print(type(s))
print(s2)
print(type(s2))
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
print(t1)
# 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
”’
print(t3[2])
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
print(lis1)
# 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])
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”)
else:
print(“b is not greater than a”)
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’}
print(my_dict)
{‘name’: ‘John’, ‘age’: 30, ‘city’: ‘New York’}
name = my_dict[‘name’]
print(name)
John
You can also add, remove, and modify the elements in a dictionary:
my_dict[‘age’] = 25
print(my_dict)
{‘name’: ‘John’, ‘age’: 25, ‘city’: ‘New York’}
my_dict[‘phone’] = ‘555-555-5555’
print(my_dict)
{‘name’: ‘John’, ‘age’: 25, ‘city’: ‘New York’, ‘phone’: ‘555-555-5555’}
del my_dict[‘phone’]
print(my_dict)
{‘name’: ‘John’, ‘age’: 25, ‘city’: ‘New York’}
Operator in Python
+ addition
x = 5
y = 3
print(x + y)
-Subtraction
x = 5
y = 3
print(x – y)
*Multiplication
x = 6
y = 3
print(x * y)
/Division
x = 12
y = 7
print(x / y)
%Modulus
x = 5
y = 2
print(x % y)
**Exponentiatio
n
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
print(x)
#answer will be 8
-=
x = 5
x -= 3
print(x)
#answer will be 2
*=
x = 5
x *= 3
print(x)
#answer will be 15
/=
x = 5
x /= 3
print(x)
%=
x = 5
x%=3
print(x)
#shows remainder 2
//
x = 5
x//=3
print(x)
#shows result in integer 2
**=
x = 5
x **= 3
print(x)
#mutiply 5*5*5
&=
x = 5
x &= 3
print(x)
Python Logical Operator
and
Logical AND: True if both the operands are true.
or
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)
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”)
n 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”)
else:
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”)
else:
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):
print(i)
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:
print(x)
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:
print(count)
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:
print(count)
count -= 1
if count == 0:
break
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.