Table of Contents
ToggleHere 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
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 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.
# This is a comment on its own line
num = 100 #num is of type int str = "Chaitanya" #str is of type string
num = 100 str = "VistaAcademy" print(num) print(str)practice in below
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
num = 10 while num>5: print(num) num -= 1
x = 20 #display x: print(x) #display the data type of x: print(type(x))
# float number fnum = 34.45 print(fnum) print("Data Type of variable fnum is", type(fnum))
#display x: print(x) #display the data type of x: print(type(x))
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))
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")
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
x = 15 y = 2 print(x // y) #the floor division // rounds the result down to the nearest whole number
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)
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 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:
# 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])
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])
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'}output
del my_dict['phone'] print(my_dict) {'name': 'John', 'age': 25, 'city': 'New York'}
# 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}
my_set = {1, 2, 3, 4, 5} my_set.add(6) print(my_set) # Output: {1, 2, 3, 4, 5, 6}
my_set = {1, 2, 3, 4, 5} my_set.remove(4) print(my_set) # Output: {1, 2, 3, 5}
my_set = {1, 2, 3, 4, 5} print(3 in my_set) # Output: True print(6 in my_set) # Output: False
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}
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") 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. 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 += 1This 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.
count = 5 while count > 0: print(count) count -= 1This 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: breakThis loop will run the same as the previous example, but it uses an infinite loop and the break statement to achieve the same result.
>def greet(name): print(f"Hello, {name}!")In this example, we’ve defined a function called greet that takes one parameter name.
greet("Alice")This will output: Hello, Alice!
def add(a, b): return a + bIn this example, the add function takes two parameters (a and b) and returns their sum.
result = add(5, 3) print(result) # This will print 8
def power(base, exponent=2): return base ** exponent
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 else: 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)) else: print(“Invalid Input”)
tasks = [] def add_task(task): tasks.append(task) print("Task added:", task) def remove_task(task): if task in tasks: tasks.remove(task) print("Task removed:", task) else: print("Task not found") def display_tasks(): print("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: ") add_task(task) elif choice == '2': task = input("Enter task to remove: ") remove_task(task) elif choice == '3': display_tasks() elif choice == '4': break else: print("Invalid Input")Function with Default Argument:
def power(x, exponent=2): return x ** exponent result = power(5) # Uses default exponent (2) print(result) result = power(3, 4) # Custom exponent (4) print(result)