Visualization using Python

Python is a powerful programming language. It can be used for developing almost all type of applications. I have used python for developing IoT applications, Data Science related applications, Statistical applications, Web Services, Automation, Networking, Web Applications, Big Data processing, visualization etc.

In this blog post, I will be introducing some of the  powerful visualization libraries available in python.

  • Pandas Visualization – The core of this library is matplotlib.
  • Matplotlib – This is one of the most popular visualization libraries in python.
  • ggplot – Based on R’s ggplot2
  • Seaborn – A data visualization library based on matplotlib. It provides a high-level interface for drawing statistical graphics.
  • Plotly – An open-source, interactive graphing library for Python

 

What is Pandas ?

Pandas is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language. Pandas comes with two primary data structures

  • Series – (One dimensional)
  • DataFrame – (Two dimensional)

These two structures helps us to handle majority of the usecases. Those who are handy with R programming language can easily implement their logic in a much powerful and better way using python pandas. Users get almost all the functionalities present in the R’s dataframe. Pandas is built on top of the popular Numpy package.

Pandas has very good timeseries data handling and processing capability. We can avoid unnecessary loops and logic by implementing pandas. It is capable of doing

  • Frequency conversion (Eg: creating 5 minute data using a dataset with 1 second frequency),
  • Data range generation
  • Moving window statistics
  • date shifting etc.

Since there are so many documents related to the pandas, I am not going to explain pandas in detail. I will be explaining some usecases with pandas implementation in my further blog posts. I will be using pandas and other scientific libraries extensively in my upcoming blog posts.

 

Basic statistics using Python

Python comes with a built-in statistics module. This will help us to perform the statistical calculations very easily.

The following are the commonly used statistical functions.

Arithmetic Mean

Arithmetic mean is the average of a group of values. The mathematical equation is

Mean = Sum of group of values / Total number of values in the group

Mean vs Average: What’s the Difference?

Answer: Both are same. No difference

Suppose we have a list of values as shown below.

values = [1,2,3,4,5,6,7,8]

For calculating the mean, without using any built-in function, we have to use the following snippet of the code

values = [1,2,3,4,5,6,7,8]
sum = 0
for value in values:
    sum += value

mean = sum/len(values)
print("Sum -->:", sum)
print("Total Count-->:", len(values))
print("Arithmetic Mean-->:", mean)

The above program involves multiple steps. Instead of writing the entire logic, we can easily calculate the mean using the following code snippet

import statistics
values = [1,2,3,4,5,6,7,8]
print("Arithmetic Mean--> ", statistics.mean(values))

Arithmetic Mode

Arithmetic mode refers to the most frequently occurred value in a data set. Mode can be calculated very easily using the statistics.mode() function

import statistics
values = [1,2,2,2,2,2,2,1,2,3,4,5,2,3,4,5,6,66,6,6,6,6]
print(statistics.mode(values))

Arithmetic Median

Median is basically the mid value in the numerical data set. The median is calculated by ordering the numerical data set from lowest to highest and finding the number in the exact middle. If the count of total numbers in the group is an odd number, the median will be the number which is in the exact middle of the ordered list. If the count of total numbers is an even number, then the median will be the mean of the numbers that reside in the middle of the ordered list.

This can be simply calculated by the statistics.median() function.

import statistics
values = [21,1,2,3,4,5,6,7,8,24,29,50]
print("Arithmetic Median--> ", statistics.median(values))