Calculate Mode in Python (4 Examples) | List & pandas DataFrame Column | Compute One / All Variables

Pubblicato il: 22 marzo 2023
sul canale di: Statistics Globe
399
4

How to find the mode in the Python programming language. More details: https://statisticsglobe.com/calculate...
Python code of this video:

my_list = ['x', 'x', 'y', 'x', 'z', 'z'] # Create example list
print(my_list) # Print example list

import statistics # Import statistics module

print(statistics.mode(my_list)) # Get mode of list

import pandas as pd # Import pandas library

data = pd.DataFrame({'x1':[5, 2, 7, 3, 4, 4, 2, 3, 2, 1, 2, 5], # Create pandas DataFrame
'x2':['y', 'x', 'x', 'z', 'x', 'y', 'y', 'x', 'z', 'x', 'z', 'x'],
'group':['A', 'C', 'B', 'B', 'A', 'C', 'A', 'A', 'C', 'B', 'B', 'A']})
print(data) # Print pandas DataFrame

print(data['x1'].mode()) # Get mode of one column

print(data.mode()) # Get mode of all columns

print(data.groupby('group').agg(lambda x:x.value_counts().index[0])) # Get mode by group

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com


In questa pagina del sito puoi guardare il video online Calculate Mode in Python (4 Examples) | List & pandas DataFrame Column | Compute One / All Variables della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Statistics Globe 22 marzo 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 399 volte e gli è piaciuto 4 spettatori. Buona visione!