---
title: std()
url: https://docs.vultr.com/python/third-party/pandas/DataFrame/std
description: Calculate Standard Deviation
publish_date: 2024-12-24T20:20:00.089627Z
last_updated: 2024-12-24T20:20:00.089627Z
header_image: https://docs.vultr.com/public/doc-assets/collection-items/1606/d57dbd0c-fb57-4f4c-8e4b-55d186fa6e02.jpg
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

# Python Pandas DataFrame std() - Calculate Standard Deviation

## Introduction
The standard deviation is a statistic that measures the dispersion of a dataset relative to its mean. In Python, the Pandas library simplifies the calculation of standard deviation across data frames with its `std()` method. This function is pivotal for data analysis, allowing for an understanding of how spread out the numerical data is in your datasets.

In this article, you will learn how to utilize the `std()` method on a DataFrame to calculate the standard deviation of various datasets. Explore how to apply this method to entire dataframes or specific columns, configure the degrees of freedom, and handle missing data effectively.

## Understanding the std() Method

### Calculating Standard Deviation on a Complete DataFrame
1. Import the pandas library and create a DataFrame.
1. Apply the `std()` method to the DataFrame to compute the standard deviation.

    ```python
    import pandas as pd

    df = pd.DataFrame({
        'scores': [88, 92, 80, 89, 90, 100],
        'age': [15, 16, 16, 15, 16, 17]
    })
    result = df.std()
    print(result)
    ```

    This code calculates the standard deviation for each numerical column in the DataFrame. 

### Using Different Degrees of Freedom
1. Recognize the significance of the degrees of freedom parameter, `ddof`. The default is 1, which calculates the sample standard deviation.
1. Adjust the `ddof` parameter as needed to compute population standard deviation.

    ```python
    population_std = df.std(ddof=0)
    print(population_std)
    ```

    Setting the `ddof` parameter to 0 computes the population standard deviation for each column, assuming the data represents the entire population.

## Applying std() on Specific DataFrame Columns

### Single Column Standard Deviation
1. Select a specific column from the DataFrame.
1. Call the `std()` method on this column to find its standard deviation.

    ```python
    score_std = df['scores'].std()
    print(score_std)
    ```

    This snippet computes the standard deviation of the `scores` column, providing insights into the variance of the scores.

### Multiple Column Standard Deviation
1. Select multiple columns by passing a list of column names to the DataFrame indexer.
1. Compute the standard deviation for the selected columns.

    ```python
    selected_std = df[['scores', 'age']].std()
    print(selected_std)
    ```

    This example computes the standard deviations of both the `scores` and `age` columns simultaneously.

## Handling Missing Data with std()

### Exclude Missing Values Automatically
1. Understand that `std()` automatically excludes NaN values from calculations.
1. Add missing values to the DataFrame and compute standard deviation.

    ```python
    df.loc[6] = [pd.NA, 18]
    result_with_na = df.std()
    print(result_with_na)
    ```

    With the `std()` function, any `NaN` or `NA` values are automatically ignored, ensuring accurate statistical calculations.

### Utilizing the `skipna` Parameter
1. Decide whether to exclude or include NaN values explicitly using the `skipna` parameter.
1. Set `skipna` to `False` to force the inclusion of NaN values in the computation.

    ```python
    result_without_skipna = df.std(skipna=False)
    print(result_without_skipna)
    ```

    Setting `skipna` to `False` will include NaN values in the computation, which may yield a NaN result if NaN exists in the data.

## Conclusion
The `std()` method in Pandas is a versatile tool for calculating the standard deviation across different segments of your data. By mastering how to apply this method, modify degrees of freedom, and handle missing values, enhance your data analysis capabilities. Implement the techniques discussed to ensure your statistical analyses are both robust and accurate. With these strategies, develop a deeper understanding of data variability and improve the quality of your analytical insights.