DEV Community

maggy njuguna
maggy njuguna

Posted on

Introduction to python for data analytics.

Introduction

Python is a programming language created by Guido van Rossum and released in 1991.The most recent version of python is python 3 which is widely used.Python was invented to simplify programming by enabling writing of simple and clear code.
Programming sounds complex but its not ,in simple terms it is the process of giving instructions to a computer on how to perform specif tasks.Python is one of the languages used to give directions to computers on how to perform tasks.

Uses of Python.

  • Python can be used on a server to create web applications -this involves designing, creating and testing software programs that can be accessed over the internet using a browser.
  • Data analysis -Python is used in data analysis to perform analysis on large data sets and create visualizations.
  • Software development -Python is used to create programs that allow users to perform tasks on a mobile phone or a computer.It has been used to create tools that automate tasks example sending automated emails or analysis of large data sets.
  • Automation -Ever gotten tired of doing the same task over and over again?, Python comes in handy and helps automate repetitive tasks example collecting customer information from a company's website.
  • Artificial intelligence and machine learning. Machine learning in simple words is teaching a computer how to perform tasks.Example teaching a computer to identify many balls and how it can be able to identify a blue ball from many balls. Artificial intelligence aims at giving computers human intelligence that is enabling them to think and make decisions like human beings.Imagine that !

Why Python is preferred over other programming languages.

  • Simple beginner friendly syntax -syntax is simply the set of rules that enable a computer to perform tasks .Python syntax is simple like the English language which makes it easy to learn.
  • Python can be used in different platforms -It runs across many operating systems without requiring major modifications.
  • Flexibility- Python can be used in many fields including automation, data analysis ,web development and artificial intelligence.
  • Global community of developers -Python has good community support which ensures availability of learning resources and quick responses to solving problems.
  • Python allows for different programming styles.
    • Procedural -the program to be followed by a computer is written step by step .
    • Object-oriented -this programming style instructions to be followed by a computer around real life objects.
    • Functional programming - it uses functions to perform calculations and analysis on data.

Python installation.
Many systems have python already installed however if your computer does not have python installed it can be downloaded from the official website.
To check on your python version run this code in your command line(cmd)
c:/users/ --python version

Python can run in various IDE(Integrated Development Environment) including; Sublime ,Visual studio code,PyCharm and jupyter notebook.

Python syntax
Python is executed using simple syntax.
print("Hello world")
Python indentation
Indentation in python is used to indicate a block of code.

Comments in python
Single line comments begin with the harsh symbol.
# perform analysis
Using docstrings for multiple lines of comments .""" or '''
Identifiers in python
An identifier is a name used to identify a variable or function.
name = "Angel"
score = 90
Name and score are identifiers used to name variables.

Variables in python
A variable in python is a name used to store a value in a program and will later be used in the program.
Name = "Maggy"
Town = "Nakuru"
Age = 15
Name, age, and town are the variables for storing Maggy, town and age.
You don't have to specify the data type in python unlike other programming languages.Python understands the data type based on the assigned value.

Differences between a variable and an identifier

  • An identifier is a name used to identify elements in a program while a variable is a name used to store a value inside a program.
  • An identifier is used to label variables and functions while a variable is used to store values that can be used later in a program.
  • An identifier does not hold data while a variable hold data.

Examples of identifiers name,age,city,score,calculate_sum

Examples of variables name = "Maggy" ,city = "kisumu"

Rules for naming variables.

  • A variable name should start with a letter or an undescore.

City = "Mombasa"

-school = "Daystar"
_number = 23

  • A variable cannot start with a number.
  • Variable names are case sensitive.
  • You cannot name a variable using python keywords.

The = (assignment operator) is used to assign value in python.
Python allows the use of multiple variables in a single line.

y, x, z = 2,3,5
print(y)
print(x)
print(z)

In python uppercase letters are used on a variable that should not change.
PI = 3.142

The type() function is used to check the type of your variable .
y = 10
print(type(x))

Data types in python
Data type is the classification of data that enables a computer identify the data its working with and the operations that be performed on that data.

  • Numeric types
    • int -these are whole numbers .

  • Floats- these are numbers with decimal points.

  • Complex -these are used in scientific computing.


Changing data types.

  • Text types
    • str - string is a sequence of characters.

  • Boolean type This data type has two possible values:True or false.

Sequence types

  • List -it is ordered ,changable and allows duplicates.

  • Tuple - it is ordered, unchangable and allows duplicates.

  • Range - represents a sequence of numbers.

Mapping types

  • Dictionaries this is a collection of key value pairs and is used to quickly look up values and organize data.

Set types

  • set- unordered and does not allow duplicates.
  • Frozen -similar to sets but unchangable.

Arithmetic operators

Comparison and logical operators in python

  • == Equals to.
  • != Not equal to .
  • > Greater than.
  • < Less than.
  • >= Greater than or equal to.
  • <= Less than or equal to.


Logical operators
The common logical operators in python include:and, or and not
and their use case is shown below.

Conclusion
It is important for every data analyst to understand python since it makes data cleaning, calculations and analysis effective.

Top comments (0)