Column Average in Record List - Python Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a list of records where each record contains multiple fields, the task is to compute the average of a specific column. Each record is represented as a dictionary or a list, and the goal is to extract values from the chosen column and calculate their average. Let’s explore different methods to achieve this.Using List Comprehension and sum()This method extracts the required column values using list comprehension and then computes the average using sum() and len(). Python # List of records records = [ {"id": 1, "score": 85, "age": 20}, {"id": 2, "score": 90, "age": 22}, {"id": 3, "score": 78, "age": 21} ] # Compute column average column = "score" values = [record[column] for record in records] average = sum(values) / len(values) # Output the result print("Average score:", average) OutputAverage score: 84.33333333333333 Explanation:The column values are extracted using list comprehension.The sum() function computes the total sum of values.The len() function counts the number of records to compute the average.Let's explore some more ways to calculate average in record list.Table of ContentUsing reduce() from functoolsUsing NumPyUsing PandasUsing reduce() from functoolsThis method uses reduce() to accumulate the sum and then divides by the length of records. Python from functools import reduce # List of records records = [ {"id": 1, "score": 85, "age": 20}, {"id": 2, "score": 90, "age": 22}, {"id": 3, "score": 78, "age": 21} ] # Compute column average column = "score" total = reduce(lambda acc, rec: acc + rec[column], records, 0) average = total / len(records) # Output the result print("Average score:", average) OutputAverage score: 84.33333333333333 Explanation:reduce() accumulates the sum of values in the given column.The final sum is divided by the number of records to get the average.Using NumPyThis method uses NumPy to convert the extracted column values into an array and compute the mean using built-in numerical operations. Python import numpy as np # List of records records = [ {"id": 1, "score": 85, "age": 20}, {"id": 2, "score": 90, "age": 22}, {"id": 3, "score": 78, "age": 21} ] # Compute column average column = "score" values = np.array([record[column] for record in records]) average = np.mean(values) # Output the result print("Average score:", average) OutputAverage score: 84.33333333333333 Explanation:numpy.array() converts the extracted values into a NumPy array.np.mean() computes the mean of the column values.Using PandasThis method utilizes pandas to store the data in a DataFrame and calculate the column average using built-in aggregation functions. Python import pandas as pd # List of records records = [ {"id": 1, "score": 85, "age": 20}, {"id": 2, "score": 90, "age": 22}, {"id": 3, "score": 78, "age": 21} ] # Convert to DataFrame df = pd.DataFrame(records) # Compute column average average = df["score"].mean() # Output the result print("Average score:", average) OutputAverage score: 84.33333333333333 Explanation:The list of records is converted into a Pandas DataFrame.The mean() function calculates the average of the specified column. Comment More infoAdvertise with us Next Article Load CSV data into List and Dictionary using Python M manjeet_04 Follow Improve Article Tags : Python Python Programs Python list-programs Practice Tags : python Similar Reads Print a List in Horizontally in Python Printing a list horizontally means displaying the elements of a list in a single line instead of each element being on a new line. In this article, we will explore some methods to print a list horizontally in Python.Using * (Unpacking Operator)unpacking operator (*) allows us to print list elements 2 min read Load CSV data into List and Dictionary using Python Prerequisites: Working with csv files in Python CSV (Comma Separated Values) is a simple file format used to store tabular data, such as a spreadsheet or database. CSV file stores tabular data (numbers and text) in plain text. Each line of the file is a data record. Each record consists of one or m 2 min read Load CSV data into List and Dictionary using Python Prerequisites: Working with csv files in Python CSV (Comma Separated Values) is a simple file format used to store tabular data, such as a spreadsheet or database. CSV file stores tabular data (numbers and text) in plain text. Each line of the file is a data record. Each record consists of one or m 2 min read Python - Records with Value at K index Sometimes, while working with records, we might have a problem in which we need to find all the tuples of elements for a particular value at a particular Kth position of tuple. This seems to be a peculiar problem but while working with many keys in records, we encounter this problem. Letâs discuss c 8 min read 3 Rookie Mistakes to Avoid with Python Lists We will see the 3 Rookie Mistakes To Avoid With Python Lists. We will discuss some general mistakes and solutions for Python Lists. 3 Rookie Mistakes to Avoid with Python ListsBelow are the 3 Rookie Mistakes To Avoid With Lists in Python: Mistake 1st: Modifying a List While Iterating Over ItOne comm 3 min read Difference between List VS Set VS Tuple in Python In Python, Lists, Sets and Tuples store collections but differ in behavior. Lists are ordered, mutable and allow duplicates, suitable for dynamic data. Sets are unordered, mutable and unique, while Tuples are ordered, immutable and allow duplicates, ideal for fixed data. List in PythonA List is a co 2 min read Like