# Python And Data Analytics: Not as Difficult as You Think

Hello everyone, I hope that you all are doing good in your life’s. The topic for today is all about data analytics with the use of python programming language. In this topic we are going to go through the fundamentals of python language first and then how we can use it in data analysis. However this blog will only cover the basics of the python programming; because main focus in on how we can use it or what are its features that act as an important role in analysis of data. So now lets start with the blog (python and data analytics) without wasting our times.

**Table of Contents**hide

### What is Python?

First of all let me make it clear that I am not taking about the but about the programming language.

Python is a paraphrased, object oriented, programmable language. It is one the most in trend programming language. It was launch by Guido van Rossum in the year 1991.

#### What is python use for

- Machine learning.
- Data Analysis.
- Connecting data base to the system.
- Web development
- and lastly Back end management.

#### Why Python?

- Simple syntax alike to English language.
- Time of execution is less, as the program length is very short as compared to other languages.
- easier to understand i.e. user friendly.
- easier to maintain.
- supportable by different software’s like Linux, Mac, Windows.
- and lastly it has a great scope in future.

### Syntax

```
print("Happy Learning")
```

Thus the result will be;

```
Output:-
Happy Learning
```

### Data Analytics

Data Analytics is certainly a process of analyzing the data i.e the raw information and then converting it into something more meaningful and insightful form of information.

Without a big Data Analytics, the organizations are like blind and deaf, wandering on the web page as if deer on the runway.

Geoffrey Moore

#### Types of Data Analytics

There are mainly four main types of data analysis which are;

- Descriptive (provides summary view of facts and figures in the simplest format for example Data visualization, Reports etc.)
- Diagnostic (examines the data to answer the questions for example Data Discovery, Data Mining.)
- Predictive (Forecast trends based on the current event for example Linear Regression, Time series)
- and lastly Prescriptive (helps to make the decision to optimize the output )

#### Elements of Data Analytics

### Python packages for Data analytics

Firstly A package is define as a collection of python modules for example;

- Numpy.
- Scipy.
- Pandas.
- Keras.
- Seaborn.
- and lastly Matplotlib.

### Starting: Python for data analytics

#### Introduction to Numpy

Numpy is one of the python module or can say the library for working with arrays. It stands for Numerical Python. Besides operations on array numpy is used for linear algebra, Fourier transforms. It provides high performance multi dimensional array object for efficient processing.

Numpy is mostly used in combination with scipy and matplotlib for complex problems. However these combination act as an alternate to MATLAB.

##### Installation

If you are using google colab, anaconda or syder for your coding then there is no need of installing numpy module as it is already present. However if you are not using any distributer then you have to install it manually. The code for installation is;

```
C:\users\your name>pip install numpy
```

##### Import

Once the module is installed the first and for most important step is to import the library by using import keyword

```
import numpy
```

However you can also import numpy as;

```
import numpy as np
```

python provides us with the option to import the numpy module as any name as we want. as shown above we have used np as an alternate name for numpy this is known as **alias**.

Certainly for creating alias we use the keyword** as**. one of the sample code is;

```
import numpy as np
#1 dimensional array
arr = np.array ([1,2,3,4])
#declaration of multi dimensional array
array = np.array ([[1, 2, 3] [4,5,6]])
```

As we have discuss before numpy is used for operation over array. Thus the array objects involve in are called as ndarray. These objects are created using simple array() function which is pre built.

#### Built in Functions

##### type()

type() is one of built in functions in python which is used to gives the type of object passed in to it. However for better understanding lets go through a sample code;

```
import numpy as np
arr = np.array([1,4,5,2])
print ("Array is of type:", type(arr))
```

```
Output
Array is of type: <class 'numpy.ndarray'>
```

##### ndim

ndim is an attribute that is use to find the dimension of the array. It usually returns a integer to denote the type; there are mainly four types i.e. 0-D, 1-D, 2-D and 3-D.

```
import numpy as np
p = np.array (42)
q = np.array ([1,2,3])
r = np.array ([[1,2,3][4,5,6]])
s = np.array ([[1,2,3][4,5,6,][7,8,9]])
print (p.ndim)
print (q.ndim)
print (r.ndim)
print (s.ndim)
```

Thus the output on the screen will be;

```
Output
0
1
2
3
```

##### Access array elements

However python is the only programming language that allows us to access us the array element with positive along with with negative index. In positive indexing we move from left to write whereas in negative indexing we move from right to left.

```
import numpy as np
arr = np.array ([1,2,3,4])
print(arr[2]) #Positive index
print(arr[-2]) #Negative index
```

Thus the result is;

```
Output
2
3
```

##### dtype

dtype is an attribute or a property that return the the data type of the object in it. for example;

```
import numpy as np
a = np.array([[1,2,3][5,6,7]])
b = np.array(['ant', 'sheep', 'hen'])
print ("The data type of array a is:", a.dtype)
print ("The data type of array b is:", b.dtype)
```

```
Output
The data type of a is: int64
The data type of b is: <U5
```

##### shape

shape is also a type of built in attribute. which is use to return a tuple with each index having maximum number of element in each dimension. For example;

```
import numpy as np
a = np.array([1,2,3]) #1-D array
print("The shape of the array a is: {a.shape}")
b = np.array([[1,2,3,4] [5,6,7,8]]) # 2-D array
print("The shape of the array b is: {b.shape}")
```

```
Output
The shape of the array a is: (3,)
The shape of the array b is: (2,4)
```

However from the above output we can conclude that the (2,4) that the first element is use to represent the no. of columns and the second element is the no. of rows.

##### copy()

```
import numpy as np
arr = np.array([1,2,3,4,5])
p = arr.copy()
arr[0] = 9
print(arr)
print(p)
```

```
Output
[9,2,3,4,5]
[1,2,3,4,5]
```

copy() is a built in attribute use to create a new and exact same array. however the changes in the new array does not effect the original array. And the changes in original will not cause any effect on the copy

##### view()

```
import numpy as np
arr = np.array([1,2,3,4,5])
p = arr.view()
arr[0] = 9
print(arr)
print(p)
```

```
Output
[9,2,3,4,5]
[9,2,3,4,5]
```

view() function is attribute which is just use to view the original array. thus any changes made in the original array will affect the viewed array. And the changes made in viewed array will affect the original array. Therefore in the above example we are getting the same output.

##### where()

where() is a function which is use to find or say search a particular element in the array. Certainly this function returns the index where the element is present. However if the element is not present in the array then we get and empty array as an output. which you will understand better in the example.

```
import numpy as np
arr = np.array([1,2,4,3,5,3,3])
x = np.where (arr==3)
print(x)
```

```
Output
(array([3,5,6]),)
```

The code above will give you a tuple as output because the particular element is present at multiple indexes. That is the value 3 is present at 3rd ,5th and 6th index.

```
import numpy as np
arr = np.array([1,2,3,4,5])
x = np.where(arr==7)
print(x)
```

```
Output
(arr([], dtype=int64),)
```

##### sort()

Sorting means just arranging the element of an array in a particular array. Thus numpy provides us with a function called sort(), that helps in sorting a particular array.

```
import numpy as np
arr = np.array ([5,3,8,1,9])
print(np.sort(arr))
```

Thus the output will be;

```
Output
[1,3,5,8,9]
```

Note:- However this function returns a duplicate copy of the original array without altering the original array.

### Conclusion

However here we are at the end of the blog. I hope that this helped to get your doubts clear and enhance your knowledge. So if you do like the blog then please do share it with others and also mention the part which you like the most. Besides if do have nay doubt then please feel free to ask down below in the comments. and also do suggest the topic which you would like to read next on.

Regards,

Have a nice day 🙂

### Read More

- Classifications of Signals and Systems and Fundamentals
- Foreword to Noise in Analog Modulation Systems
- Overture to Magnetic Circuits | Self and mutual inductance
- Best of Programmable Logic Devices
- Preface for 3-Phase Induction Motors
- Synopsis of Frequency Response & Filter Circuits
- Top Analysis of DC Circuits | Electrical Network | Part-2

## No Comments