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

preview_player
Показать описание
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

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

Follow me on Social Media:

Рекомендации по теме