filmov
tv
Summary Statistics by Group of pandas DataFrame (3 Examples) | Multiple Groups & Subgroup Column
Показать описание
Python code of this video:
import pandas as pd # Import pandas library to Python
data = pd.DataFrame({'x1':[1, 7, 5, 3, 7, 2, 7, 9], # Create pandas DataFrame
'x2':range(0, 8),
'group1':['A', 'B', 'B', 'A', 'C', 'C', 'B', 'A'],
'group2':['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b']})
print(data) # Print pandas DataFrame
# x1 x2
# group1
# A 4.333333 3.333333
# B 6.333333 3.000000
# C 4.500000 4.500000
# x1 x2
# group1 group2
# A a 2.0 1.5
# b 9.0 7.0
# B a 6.0 1.5
# b 7.0 6.0
# C b 4.5 4.5
# x1 ... x2
# count mean std min 25% ... min 25% 50% 75% max
# group1 ...
# A 3.0 4.333333 4.163332 1.0 2.00 ... 0.0 1.50 3.0 5.00 7.0
# B 3.0 6.333333 1.154701 5.0 6.00 ... 1.0 1.50 2.0 4.00 6.0
# C 2.0 4.500000 3.535534 2.0 3.25 ... 4.0 4.25 4.5 4.75 5.0
Follow me on Social Media:
import pandas as pd # Import pandas library to Python
data = pd.DataFrame({'x1':[1, 7, 5, 3, 7, 2, 7, 9], # Create pandas DataFrame
'x2':range(0, 8),
'group1':['A', 'B', 'B', 'A', 'C', 'C', 'B', 'A'],
'group2':['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b']})
print(data) # Print pandas DataFrame
# x1 x2
# group1
# A 4.333333 3.333333
# B 6.333333 3.000000
# C 4.500000 4.500000
# x1 x2
# group1 group2
# A a 2.0 1.5
# b 9.0 7.0
# B a 6.0 1.5
# b 7.0 6.0
# C b 4.5 4.5
# x1 ... x2
# count mean std min 25% ... min 25% 50% 75% max
# group1 ...
# A 3.0 4.333333 4.163332 1.0 2.00 ... 0.0 1.50 3.0 5.00 7.0
# B 3.0 6.333333 1.154701 5.0 6.00 ... 1.0 1.50 2.0 4.00 6.0
# C 2.0 4.500000 3.535534 2.0 3.25 ... 4.0 4.25 4.5 4.75 5.0
Follow me on Social Media: