# python-scipyHow do I use Python Scipy to perform a Z test?

`Scipy`

is a library for scientific computing in Python. It provides functions for performing various statistical tests, including the Z-test.

To use `Scipy`

to perform a Z-test, you will need to import the `stats`

module. This module contains the `ztest`

function which can be used to perform the Z-test.

```
from scipy import stats
z_score, p_value = stats.ztest(x1, x2)
```

The `ztest`

function takes two arguments, `x1`

and `x2`

which are the two samples being compared. It returns two values, the `z_score`

and the `p_value`

. The `z_score`

is the standardized test statistic and the `p_value`

is the probability of obtaining the observed results, given that the null hypothesis is true.

## Code explanation

`from scipy import stats`

- imports the`stats`

module from the`Scipy`

library.`z_score, p_value = stats.ztest(x1, x2)`

- calls the`ztest`

function from the`stats`

module, passing in two samples`x1`

and`x2`

as arguments. It returns two values,`z_score`

and`p_value`

.

## Helpful links

### More of Python Scipy

- How do I create a 2D array of zeros using Python and NumPy?
- How do I use Python XlsxWriter to write a NumPy array to an Excel file?
- How can I use Python and SciPy to find the zeros of a function?
- How do I use Python Numpy to read and write Excel (.xlsx) files?
- How do I uninstall Python Scipy?
- How do I create a numpy array of zeros using Python?
- How can I use the Radial Basis Function (RBF) in Python with SciPy?
- How do I create a zero matrix using Python and Numpy?
- How can I use the x.shape function in Python Numpy?
- How do I perform a t-test using Python and SciPy?

See more codes...