deepwzh的技术笔记
  • Golang
  • Python
  • Cpp
杂项
前端开发
  • 计算机网络
  • 操作系统
  • 数据库
云原生
Devops
AIGC
关于作者
  • Golang
  • Python
  • Cpp
杂项
前端开发
  • 计算机网络
  • 操作系统
  • 数据库
云原生
Devops
AIGC
关于作者
  • Python
  • 魔术方法
  • pep 草案
  • 内存管理
  • 学习资料

    • 学习资料
    • 进阶学习资料
  • Asyncio

    • Asyncio
    • 调度
  • 库

    • 库
    • 模板渲染相关
    • protobuf 相关
    • mysql 相关
  • cpython开发

    • cpython 开发
    • 开发环境搭建
    • CAPI
    • 提交流程
    • Pyrepl
  • 包与虚拟环境管理器

    • 包与虚拟环境管理器
    • Pip
    • Conda
    • Poetry
    • Pyenv
  • 科学计算相关

    • 科学计算相关
    • Pandas

Pandas

示例

时序数据分析

data = [{"time": "2022-04-01T12:09:46.929+0800", "op": "query", "cost": 100, "db_name": "dbname"}]
df = pd.DataFrame(data=df_data, columns=["time", "op", "cost", "db_name"])
df["time"] = pd.to_datetime(df["time"])
df.set_index("time", inplace=True)
df["cost"] = df["cost"].astype(int)_
_pd.set_option("display.max_rows", None)
time_group = df["2022-04-01 00:00:00":"2022-04-01 23:59:05"].groupby("db_name").resample("60Min")_
_print(time_group.apply(lambda x: pd.Series({ "avg_cost": x["cost"].mean(), "max": x["cost"].max(),  "max_arg": x["cost"].idxmax() if not x["cost"].empty else None, "min": x["cost"].min(), "min_arg": x["cost"].idxmin() if not x["cost"].empty else None, "median": x["cost"].median(), "count": x["cost"].count() })))
Prev
科学计算相关