Machine Learning with Python Cookbook by Kyle Gallatin and Chris Albon

Machine Learning with Python Cookbook by Kyle Gallatin and Chris Albon

Author:Kyle Gallatin and Chris Albon
Language: eng
Format: epub
Publisher: O'Reilly Media, Inc.
Published: 2022-10-05T00:00:00+00:00


3.8 Finding the Minimum, Maximum, Sum, Average, and Count

Problem

You want to find the min, max, sum, average, or count of a numeric column.

Solution

pandas comes with some built-in methods for commonly used descriptive statistics such as min, max, mean, sum and count:

# Load library import pandas as pd # Create URL url = 'https://raw.githubusercontent.com/chrisalbon/sim_data/master/titanic.csv' # Load data dataframe = pd.read_csv(url) # Calculate statistics print('Maximum:', dataframe['Age'].max()) print('Minimum:', dataframe['Age'].min()) print('Mean:', dataframe['Age'].mean()) print('Sum:', dataframe['Age'].sum()) print('Count:', dataframe['Age'].count())



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.