×

EDA in Python

The EDA is the exploratory data analysis; the data scientists mainly use the EDA to understand the main features of the data quickly, the variables in python and the relationship between them, and it also helps identify the important variables to our problem statement. The data analysis can be done in both a graphical and a non-graphical manner. The graphical method includes organizing the data in bar graphs, scatter plots and correlation plots. The non-graphical method includes organizing the data in the form of the data frames and with many other functions such as shape, isnull and other datatypes. The data organization is generally divided into three types.

  1. Descriptive Statistics
  2. Group data
  3. ANOVA
  4. Correlation plots and methods.

Descriptive Statistics: This method is used to organize the data descriptively, giving brief details of the data with the help of some methods and variables in the languages.

Group data: This method includes the data in the form of groups. Each data is divided into different groups based on different characteristics.

ANOVA: It is the statistical method of organizing the data based on the variance of the data. The ANOVA test is mainly used to accept the data based on the null hypothesis and reject the data in the alternate hypothesis.

Correlation plots and methods: The correlation plots are used to compare one group of data with the other form of the data in the graphical form based on the regression coefficient; the correlation plots are plotted mainly with the help of the scatter.plot( ) methods.

Descriptive Statistics

Descriptive statistics are mainly used to understand the data in a more accessible manner quickly. In python, pandas consist of the describe( ) method or function to organize the data. The describe function helps perform the statistical operations on the data, such as standard deviation, the total number of data values in the given data, the mean of the data, and the minimum and maximum values of the provided data.

Syntax:

DF.describe( )

Example:

Now let us find all the statistical values of the different data sets in the given data with the help of describe( ) function. To perform this operation first, we need to import the libraries such as pandas and numpy, and then we need to collect the data in the form of pandas dataframe then, with the help of describe( ) function, we can find all the statistical values of the given series of data.

Code:

#Importing the libraries 
import pandas as pd
import numpy as np


#collecting the data in the form of arrays
data = np.array([10, 20, 30, 40, 50], [3, 5, 7, 9, 11], [10, 15, 20, 25, 30])


#Arranging the data in the form of dataframe
DF = pd.DataFrame(data)


#Using the describe function
DF.describe()

Output:

              age 	pages        students_class
count 55      5
mean          30           720
min          10            3	              10
max          50           11                   30
std          15.8         3.16              7.905
25%          12.5	 2.75	             7.5
50%           25	 5.5	              15
75%           37.5	 8.25                22.5

We also have another function or method, value_counts( ), which is used to calculate the statistical data about each category. If we contain a series of data in a given dataframe, we can calculate all the statistical values of a particular data series using the value_count( ) function.

To perform this operation, first, we need to import the libraries such as pandas and numpy, and then we need to collect the data in the form of a pandas dataframe; then, with the help of the value_counts( ) function, we can find all the statistical values of the given set of values in the given dataframe.

Example:

#Importing the libraries 
import pandas as pd
import numpy as np


#collecting the data in the form of arrays
data = np.array([10, 20, 30, 40, 50], [3, 5, 7, 9, 11], [10, 15, 20, 25, 30])
#Arranging the data in the form of dataframe
DF = pd.DataFrame(data)
#Using the value_counts( ) function
DF[“age”].value_counts( )

Output:

	age
count     5
mean     30
min 	10
max	50

              In descriptive statistics, we have another boxplot method: the graphical representation of the data in the form of bar plots. To perform this operation, we need to import the matplotlib library. This is the best method because we can understand the data easily in the pictorial form.

Code:

#importing the libraries
import pandas as pd
import matplotlib.pyplot as plot


#Collecting the data
DF = pd.read_csv(“data”)


#Collecting the data in the form of list
x = list(DF.population)


#plotting the data
plt.boxplot(x)


#displaying the data
plt.show( )

Output:

EDA in Python

Here we can easily find the mean of the data from the bar plot, we can find the maximum value from the plot and also we can easily find the minimum plot of the data. This is the most efficient way of organizing the data and finding the statistical measures of the data quickly.

Group Data

This type of method is very effective, available in python pandas and helps calculate all the statistical data of the given dataset. We can also find the statistical calculation of each set separately, such as we can find the mean and we can also find the standard deviation of the data separately.

Syntax:

#For finding the mean of a group of data
DF.group([group_name]).mean( )


#For finding the standard deviation of the group of data
DF.group([group_name]).deviation ( )

Parameters:

DF: Data frame in the pandas

Group: Name of the dataset

group_name: The name of the group in the dataset

Example:

#Importing the libraries 
import pandas as pd
importnumpy as np


#collecting the data in the form of arrays
data = np.array([A, C, D], [P, Y, T, H, O, N])


#Arranging the data in the form of dataframe
DF = pd.DataFrame(data)


#Using the mean function
DF.group([‘age’, ‘pages’]).mean

Output:

                         Population   income
age       pages        
A         P              12334.22	18792
          Y            12345.33         12344
          T             13469.32        54567
          H             15672.89	43246
          O             13468.98	12345
          N              16789.78	17896
C         P		17678.88	12345
          Y		15676.76	17678		
          T	        13456.76	16854
	H	        14567.78	16532	
	O	        16574.67	18743
	N	        19875.55	17643
D	P	        20876.22	16543
	Y               21345.78	19752	
	T	        14567.88	66561
	H	        16775.99	17642
	O	        17665.98        13345	
	N	        21338.87	97643

Here we can find the mean of the group by group data using the group data. In the same way, we can find the variation of the data using the group data. So we can say that the group data method is the most efficient way of finding the statistical values of the data.

ANOVA

It is the statistical method of organizing the data based on the variance of the data. The ANOVA test is mainly used to accept the data based on the null hypothesis and reject the data in the alternate hypothesis.We first need to import the scipy libraries to perform the ANOVA operation. Then we need to collect the data in the form of lists or any data type in python; with the help of the f_oneway( ) function, we can perform the one-way ANOVA test and analyze the data. The ANOVA will return two test results they are:

  • F– testscore: This method will calculate the variation of the group means over the total variation of the data.
  • p-value:This method will return the main result of the given data. This operation can be performed by importing the scipy module and with the help of the f_oneway( ).

Syntax:

f_oneway(datatypes)   

Parameters:

Datatypes: These are the data for which we need to find the statistical values of the values.

Example:

#Importing the library
fromscipy.stats import f_oneway


#values for which we need to find the statistical values of the data.
Value1 = [76, 65, 55, 87, 66]
Value2 = [55, 87, 66, 79, 90]
Value3 = [67, 98, 32, 76, 92]


#using the f_oneway function to perform the one-way ANOVA
f_oneway( Value1, Value2, Value3 )  

Output:

F_onewayResult(statistic=2.54678832, pvalue= 0.0365488686)

From the output, we can find the Fstatistic data and p-value are 2.55 and 0.03. As we can find that the p-value is less than 0.05 so, we need to reject the null hypothesis, we need to reject the null hypothesis.

Correlation plots and methods:

  The correlation plots are used to compare one group of data with the other form of the data in the graphical form based on the regression coefficient; the correlation plots are plotted mainly with the help of the scatter.plot( ) methods.

This method can be analyzed using graphical and non-graphical ways of analyzing the data. The Pearson method is the non-graphical method of analyzing the data. To analyze the data, we require the Pearson coefficient and the p-value; the data are said to be strongly correlated if the Pearson coefficient is near 1 or -1 and if the p-value is less than 0.001.


Related Topics

Static Variables in Python

What is a Static Variable? The variable that remains with a constant value throughout the program or throughout the class is known as a " Static Variable ". Static variables are...

3 minutes read.

Filter List in Python

Python: Python is one of the most used programming languages, as it is used widely in software and data analysis, web development, etc. It is said to be a user-friendly programming...

3 minutes read.

Standard Scaler in SKLearn

The sci kit learns in python is a library thatch is used in machine learning which is used to work on data modeling.It is only focused on the data modeling,...

4 minutes read.

Python Dictionary fromkeys() method

Python Dictionary fromkeys() method The dictionary.fromkeys() method in Python creates a new dictionary from the given sequence of elements and returns a dictionary with the specified keys and values. Syntax dictionary.fromkeys(sequence[, value]) Parameter sequence- This...

1 minute read.

Python try catch exception

The try-except proclamation can deal with exceptions. Exceptions might happen when you run a program. Exceptions are blunders that occur during the execution of the program. Python won't educate you regarding...

3 minutes read.

os.rename() method in Python

In Python, the os module provides the capacity to interact with the operating system. The operating system comes under the Python module. In this module, Python provides a specific feature...

3 minutes read.

Python List copy() method

Python List copy () method The list.copy () method returns a shallow copy of the list. Syntax list.copy() Parameter NA Return This function returns the copy for the given list. Example 1 # Python program explaining # the list.copy() method # passing the...

1 minute read.

Read JSON File in Python

JSON refers to the JavaScript Object Notation. It is a Data format used for representing structured data and it is used to transfer and store data. In JSON format, the...

5 minutes read.

Python Dictionary keys() method

Python Dictionary keys() method The dictionary.keys() method in Python returns a view object that displays a list of all the keys in the dictionary Syntax dictionary.keys() Parameter NA Return This method returns a view object that displays...

2 minutes read.

Python Examples

In this tutorial, we will see some examples related to python. This will include some basic example questions and their code in Python. Write a program to print “Hello Python”. print(‘Hello Python’) Output Hello...

5 minutes read.

Python Euclidean Distance

Euclidean distance is the distance between two points with whatever of dimensions. We are using NumPy library to find and calculate the Euclidean distance. The NumPy library is used for...

1 minute read.

Pillow Python introduction and setup

Introduction Advanced image processing implies handling the picture carefully with the assistance of a PC. Utilizing picture handling we can perform activities like upgrading the picture, obscuring the picture, separating text...

4 minutes read.

Data Structures and Algorithms Using Python | Part 1

Data Structures: Data Structure is defined as a way to organize and store the data so that we can access the data and work more efficiently. Data structures also describe the...

18 minutes read.

Python Set clear() Method

Python Set clear() Method The set.clear() method removes all the elements from the set. Syntax set.clear() Parameter NA Return None Example 1 # Python program explaining # the set.clear() method # initializing the set fruits = {"watermelon", "banana", "apple"} # printing the set...

2 minutes read.

Python Breakpoint

Introduction In Python 3.7, a brand-new created function called breakpoint() was added. Due to the close relationship between both the executable and the code of a debugging component, debugging Python programming...

4 minutes read.

Python Program to Generate a Random String

The term "random" refers to a group of information or data that can be accessed in any chronological order. To create random strings, a Python program called random is utilized....

6 minutes read.

Python Line Break

Introduction In this tutorial, you will learn line breaks in python.In Python, the new line character is used to indicate the start of a new line and the end of an...

5 minutes read.

Python Win32 Process

The Win32 process is essentially a Python procedure. This program provides access to advanced Win32 process creation and management features. Process objects are created through the Create method (the constructor)....

6 minutes read.

How to slice a list in python

When working with lists, we face situations where we may need a part of the list from one index to the other. Slicing is one of the simpler ways to...

5 minutes read.

What is Python online compiler?

The compiler is a program that is used to scan an entire high-level program (source code) and it translates the scanned program into machine code. Compilers convert .py source code into...

5 minutes read.