DataFrame(5):聚合计算
1、读取数据
import pandas as pd import numpy as np import os import shutil import dateutil wd = os.getcwd() os.listdir(wd) path='/Users/xiaoli.zhang/Documents/材料/LearnP' os.chdir(path) wd = os.getcwd() display(wd) data=pd.DataFrame(pd.read_excel('test.xlsx')) display(data)
2、计算函数
Function | Description |
---|---|
count | Number of non-null observations |
sum | Sum of values |
mean | Mean of values |
mad | Mean absolute deviation |
median | Arithmetic median of values |
min | Minimum |
max | Maximum |
mode | Mode |
abs | Absolute Value |
prod | Product of values |
std | Unbiased standard deviation |
var | Unbiased variance |
sem | Unbiased standard error of the mean |
skew | Unbiased skewness (3rd moment) |
kurt | Unbiased kurtosis (4th moment) |
quantile | Sample quantile (value at %) |
cumsum | Cumulative sum |
cumprod | Cumulative product |
cummax | Cumulative maximum |
cummin | Cumulative minimum |
3、groupby 输出 DataFrame格式
4、agg(),多个聚合函数
5、多分组多个聚合
6、重命名(剔除index)