# Statistical Analysis in Odoo using NumPy

In this post, we’ll look at how to use the NumPy library in Odoo to perform statistical analysis for price variability. We’ll also extend Odoo’s functionality by calculating the average and standard deviation of the product’s price and showing it in the Odoo UI. This can be useful for businesses to understand their pricing strategy and product pricing variability.

__NumPy Library__

NumPy is a Python package that is used for Numerical computation, and NumPy stands for Numeric Python

__How to install Numpy?__

### Installation

The numpy package is installed using the pip command. Run the following command in the “pycharm” terminal

** pip install numpy**

If you don’t have Pip on your system, you should first install Pip.

**Import NumPy**

To import the numpy package into our Python code, we need to use the command **import numpy as np**

**A breif review about Mean and Standard Deviation**

__Mean(____):__

The Formula to calculate the Mean for a set of data values x_1,x_2,….,x_n is μ=1/n ∑_(i=1)^n

Mean gives the central value of the given data points.

__Standard Deviation(____):__

SD is a measure of the dispersion or variability of a dataset. It calculates how far data points are, on average, from the mean.

Standard Deviation about the central mean value for a set of data points x_1,x_2,….,x_nis σ=√(1/n ∑_(i=1)^n

**Calculating Mean and Standard Deviation using the Numpy**

Without needing to directly calculate the Mean and the Standard Deviation using the formula we can implement the inbuilt function within the NumPy library. The code for calculating the **Mean** and **Standard Deviation** for a set of data points is **np.mean() **and **np.std(). **As an example, I have provided a code that calculates the Mean and Standard Deviation for a list **l=[1,2,3,4,5,6]**

** Applying Mean and Standard Deviation in the Sales Module of Odoo**

In the sales module, I have applied NumPy to calculate the Mean price and the Price deviation of a set of products given in the form view of the Sales Order Line. As you can see in the Odoo UI, I have added a field of Mean Price and Standard Deviation in the Sales Form view.

In the sales Order line, you can see the ordered products and their respective price. Upon confirmation of the order, a **Mean and Price deviation** button appears at the header of the sales form view. On clicking that button, we get the current mean price and price deviation of the ordered products.

As you can see from the image, the Calculated Mean price is = 136 $ and the Standard Price Deviation is $102. Here, the value of the Standard Price Deviation gives us a rough idea that there is a high to moderate fluctuation in the sales price of each selected product.

The Python Code that I implemented for this specific purpose is:

In this code, it’s evident that we don’t employ explicit equations for computing the Mean and Standard Deviation of product prices. We condensed the code significantly by utilizing NumPy’s mean and Standard Deviation functions.

In today’s world. Product prices are constantly changing, so it’s important to keep an up-to-date understanding of what’s happening in order to make informed decisions. With the help of statistical analysis, you can get a better understanding of your pricing landscape with the help of integrating NumPy with Odoo. By integrating statistical analysis directly into the Odoo platform, you can make data-driven decisions that drive profitability and market competitiveness.

## "Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote