Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

average value of list elements in python

# Example to find average of list
number_list = [45, 34, 10, 36, 12, 6, 80]
avg = sum(number_list)/len(number_list)
print("The average is ", round(avg,2))
Comment

mean of a list python

import numpy as np
np.mean(list)
np.std(list)
Comment

find average of list python

list = [15, 18, 2, 36, 12, 78, 5, 6, 9]

# for older versions of python
average_method_one = sum(list) / len(list) 
# for python 2 convert len to a float to get float division
average_method_two = sum(list) / float(len(list))

# round answers using round() or ceil()
print(average_method_one)
print(average_method_two)
Comment

python get average of list


#python3

def average(list): 
    result = sum(list) / len(list) 
    return result 

list = [68,68,71,71,71,75,71,78,91,98,75,71,84]
print(average(list))
Comment

python find the average of a list

numbers = [3, 18, 2, 1, 70, 12, 36, 12, 78, 5, 6, 9]

import statistics

print(statistics.mean(numbers))
Comment

mean of a list python

l = [15, 18, 2, 36, 12, 78, 5, 6, 9]

# By using the built-in statistics library
import statistics
statistics.mean(l)  # 20.11111111111111

# By defining a custom function
def average(my_list):
  return sum(my_list) / len(my_list)
average(l) # 20.11111111111111
Comment

average of a list in function with python

def lol(a):
	x = sum(a)/len(a)
	print(x)
lol([5,7,3,9,4])
Comment

PREVIOUS NEXT
Code Example
Python :: how to use if else in lambda python 
Python :: pandas bin columns 
Python :: python how to get user input 
Python :: drop duplicate index pandas 
Python :: python version check in cmd 
Python :: Select rows in pandas MultiIndex DataFrame 
Python :: how to open a file with python 
Python :: delete database entry using name django 
Python :: library for converting text into image in python 
Python :: date.month date time 
Python :: split data train, test by id python 
Python :: python key list 
Python :: radix sort in python 
Python :: first column of a dataframe python 
Python :: python add field to dictionary 
Python :: clone website in python 
Python :: How to select rows in a DataFrame between two values, in Python Pandas? 
Python :: how to use global variable in python 
Python :: df dropna 
Python :: pyspark dropna in one column 
Python :: make a white image numpy 
Python :: socket io python 
Python :: difference between for loop and while loop in python 
Python :: pandas data profiling 
Python :: Python remove punctuation from a string 
Python :: import get object 
Python :: python code for where to save the figures 
Python :: select rows from dataframe pandas 
Python :: what does int do in python 
Python :: split datetime to date and time pandas 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =