In Pandas, what method is used to calculate summary statistics for numerical columns in a DataFrame?

groupby()
value_counts()
describe()
reshape()

The correct answer is C. describe().

The describe() method returns a DataFrame containing basic statistics for each numeric column in the DataFrame. The statistics include the count, mean, standard deviation, minimum, maximum, and 25th and 75th percentiles.

The groupby() method groups the DataFrame by a specified column or columns and then calculates summary statistics for each group.

The value_counts() method counts the number of times each unique value appears in a column.

The reshape() method changes the shape of a DataFrame by reshaping the columns or rows.

Here is an example of how to use the describe() method:

“`
import pandas as pd

df = pd.DataFrame({‘A’: [1, 2, 3, 4, 5], ‘B’: [6, 7, 8, 9, 10]})

df.describe()

A B

count 5 5

mean 3.0 7.0

std 1.4142135623730951 2.8284271247461903

min 1.0 6.0

max 5.0 10.0

25% 2.5 7.5

75% 3.5 8.5

“`

Exit mobile version