pandas:pandas的统计分析

  先导入模块,并加载数据

import pandas as pd
detail = pd.read_excel("./meal_order_detail.xlsx")

  detail的列索引有:

 pandas的统计分析:

(1)最大值、最小值

print("获取最大值:\n",detail.loc[:,["amounts","counts"]].max())
print("获取最小值:\n",detail.loc[:,["amounts","counts"]].min())

(2)平均值、中位数

print("获取均值:\n",detail.loc[:,["amounts","counts"]].mean())
print("获取中位数:\n",detail.loc[:,["amounts","counts"]].median())

(3)标准差、方差

print("获取标准差:\n",detail.loc[:,["amounts","counts"]].std())
print("获取方差:\n",detail.loc[:,["amounts","counts"]].var())

(4)非空数据的数量

print("获取非空数据的数量:\n",detail.loc[:,["amounts","counts"]].count())

(5)最大值最小值所在位置

print("获取最大值的位置:\n",detail.loc[:,["amounts","counts"]].idxmax())
print("获取最小值的位置:\n",detail.loc[:,["amounts","counts"]].idxmin())

(6)众数

# 返回一个众数的dataframe
res = detail.loc[:, ["amounts", "counts"]].mode()
print("获取众数\n", res["counts"])
print("获取众数\n", type(res))
# 返回一个 众数的 series
print("获取众数\n", detail.loc[:, "amounts"].mode())

(7)分位数

# 默认获取 50% 的分位数---即 中位数
print("获取分位数:\n", detail.loc[:, ["amounts", "counts"]].quantile())
# 获取四分位数 --通过给q 传参来获取四分位数
print("获取分位数:\n", detail.loc[:, ["amounts", "counts"]].quantile(q=np.arange(0, 1 + 0.25, 0.25)))

猜你喜欢

转载自www.cnblogs.com/xmcwm/p/11854802.html
今日推荐