Python for Data Science

DS - VRP
4 min readMar 1, 2021

Why Python?

Python is a general-purpose programming language that is becoming ever more popular for data science. Python also lets you work quickly and integrate systems more effectively. Companies from all around the world are utilizing Python to gather bits of knowledge from their data. if you want to learn more please click here.

Data science is solving business problems by using data. To learn more about data science please click here.

Variables: Variables are used to store values. The variable in a python program gives data to the computer for processing. It can consists of various data types and data structures.

Date Types:

Different data types in python.

We can perform various arithmetic operations in python. They are

Operators in python.

String: A string in Python is a sequence of characters. It is a derived data type. Strings are immutable. This means that once defined, they cannot be changed. It is created with the help of parenthesis().

the syntax for the list is

Image showing the string with input and output.

We cannot update the string once it is created.

List: List is ordered data structure of mixed data types in python which is used to store values. Lists are created by using a Square bracket []. It is a mutable type of data structure. It means it can be changed.

the syntax for the list is

Image showing the list with input and output.

As it is mutable data type is can be updated according to need. Thus we can perform many operations with lists.

Tuple: Tuple is an ordered data structure of mixed data types in python which is used to store values. Tuples are created by using parentheses(). It is an immutable type of data structure. It means it cannot be changed.

the syntax for the tuple is

Image showing the Tuple with input and output.

Dictionary: A dictionary stores element as keys and values pairs. The key is like an index, it is always unique and immutable. The values are the objects that contain information. Values are accessed using their keys. Each key is followed by a value separated by a colon. The values can be immutable, mutable, and duplicates. It is created by using the curly brackets{}.

The syntax for the dictionary is

Image showing the Dictionary with input and output.

Sets: Sets are a type of collection like lists and tuples, storing mixed data. Sets are enclosed within curly brackets and elements are written as comma-separated. Sets are unordered. Sets do not allow duplicates.

The syntax for sets is:

Image showing the Sets with input and output.

Please click to learn more operations on these data structures.

Loops

Loops play a vital role in executing any task. It can help us to reduce the code lines and complete the task in an efficient way.

There are two types of loop

  1. For loop: For loop is used to iterate over a sequence. It works on List, tuple, dictionary, string and set data structures.

The syntax of for loop is :

The Syntax for the For Loop.

2. While loop: The while statement allows you to repeatedly execute a block of statements as long as a condition is true. A while statement is an example of what is called a looping statement. A while statement can have an optional else clause.

The Syntax for While loop is

This image contains the syntax for the while loop.

Functions: Functions are reusable piece of software. Block of statements that accepts some arguments, perform some functionality and provides the output. Defined using the def keyword. A function can take arguments.

The Syntax for the Function:

This is the syntax for the Function.

Please click here to know more about the functions.

Below are the 50+ python tricks which can be useful

Thank you

--

--

DS - VRP

A budding data scientist who is learning and evolving everyday