DEV Community

Cover image for Introduction to Python for Data Science
Nginacloud
Nginacloud

Posted on

Introduction to Python for Data Science

Python101
Python is high-level a programming language created for specific task but can be used across a wide range of domain, general purpose language.
It has its standard library built-in modules making it an easy and simple language to learn.

Syntax and Semantics in python

Compared to other languages like java, python syntax is written in English making it easier to write, read and understand.
Python has fewer syntactic exceptions and special cases like curly brackets {} are allowed but rarely used.
Here are the top concepts to master for your data career

Indentation and whitespaces
Python uses indentation rather than curly brackets{} to structure its code. Indentation is the spaces at the beginning of a code line.

 if 5 > 2
  print('five is greater than two')
Enter fullscreen mode Exit fullscreen mode

Identifiers
These are user defined names used to identify variables, module, class, function or other object.

Rules followed in defining identifiers
*cannot start with a number
*no spacing
*name can be a letter A to Z, a to z or an underscore(_)
*name can be followed by zero or more letters, underscore or digits (0 to 9)
*case sensitive

Comments
Statements used to describe a code.
Hash (#) is used to mark a comment.

#This in a comment
 print("To more life!")
Enter fullscreen mode Exit fullscreen mode

variables
Basically, this a container that stores data values.
Created when you assign a value to it

x = 2
y = 'word'
 print(x)
 print(y) 
Enter fullscreen mode Exit fullscreen mode

casting
Specifying the data type of a variable

x = float(9)  #x will be 9.0
y = str(4)  #y will be '4'
Enter fullscreen mode Exit fullscreen mode

Variables are case-sensitive

a = 4
A = 9.0   #A will not overwrite a
Enter fullscreen mode Exit fullscreen mode

Rules followed when naming variables
*Variable names should start with a letter or an underscore (_). *They cannot start with a number.
*Variable names can only contain letters, numbers, and underscores. They cannot contain any other special characters such as !, @, #, $, %, etc.
*Variable names are case sensitive. For example, "myVar" and "myvar" are two different variables.
*Variable names should be descriptive and meaningful.
*If a variable name consists of multiple words, it is recommended to use underscores to separate the words. For example, "first_name" instead of "firstname".
*It is not recommended to use built-in keywords or function names as variable names. For example, "print" is a built-in function in *Python, so it should not be used as a variable name.

String
Strings are made unique from integers but surrounding them with single or double quotation marks.

print("String")
print('integer')
Enter fullscreen mode Exit fullscreen mode

Booleans values
These are mainly known as an expression of True or False
When you run a condition of an if statement, Python returns True or False.

a = 200
b = 33

if b > a:
  print("b is greater than a")
else:
  print("b is not greater than a")
Enter fullscreen mode Exit fullscreen mode

Arithmetic Operations
The (+) symbol represents addition.
The (-) symbol represents subtraction
The () symbol represents multiplication.
The (/) symbol represents division.
The (%) is used to express the modulus- this produces a remainder of the integer division
The (
*) symbol represents an exponent- raises a number to the power of another
The (//) symbol represents floor division- returns the whole number part of the division.

Functions
This is a block of code which runs when called. It is defined using the def keyword.

def my_function():
 print("Hello World")
my_function()
Enter fullscreen mode Exit fullscreen mode

Arrays
A variable that can hold more than one value at a time.
Python does not have a built-in support for arrays but python lists can be used instead.

Development Environment

These are software platforms that facilitate to maximize programmer productivity.
They are commonly the Integrated Development Environment (IDEs).
Examples of such are the visual studio code, Jupyter Notebook, Spyder etcetera.
They help programmers code and debug programs easily.

Why python?

Many frameworks and libraries- saves time and effort in development examples, NumPY and Pandas.
Reliability and speed.
Easy to learn and use- it is the common first-language choice for developers or students.

What can python do

Due to python's simplified syntax, it has been adopted by programmers for tasks like;
AI and machine learning
Data Visualization
Programming Applications
Web Development
Game Development
among others.

Top comments (0)