当前位置: 首页 > news >正文

【数据分析】python-pandas速查文档(3)

python-pandas速查文档(3)

博客主页:源码速查
本文档共 4 部分,当前为第 3 部分

文章目录

  • python-pandas速查文档(3)
    • 六、公开方法速查(按功能分类)
        • equals():对象相等判断
        • eval():表达式计算
        • factorize():因子编码
        • floor():时间向下取整
        • floordiv():整除运算
        • flush():刷新到磁盘
        • format():格式化输出
        • fromordinal():序数转时间戳
        • fromtimestamp():秒数转时间戳
        • ge():大于等于比较
        • gt():大于比较
        • holds_integer():是否存整数值
        • identical():严格相同判断
        • indexer_at_time():特定时间定位
        • infer_freq():推断频率
        • infer_objects():推断对象类型
        • intersection():交集
        • is_boolean():布尔类型判断
        • is_categorical():分类类型判断
        • is_dtype():类型匹配判断
        • is_floating():浮点类型判断
        • is_integer():整数类型判断
        • is_numeric():数值类型判断
        • is_object():对象类型判断
        • isetitem():按位置设置值
        • isna():缺失值检测
        • isnull():缺失值检测(同义)
        • isocalendar():ISO日历信息
        • isoweekday():ISO星期序号
        • items():逐列迭代
        • iterrows():逐行迭代
        • itertuples():命名元组迭代
        • keys():HDF5键列表
        • kurt():峰度系数
        • kurtosis():峰度(同义)
        • le():小于等于比较
        • list():列表访问器入口
        • lreshape():宽表转长表
        • lt():小于比较
        • mod():取余运算
        • mode():众数
        • month_name():月份名称
        • mul():乘法
        • multiply():乘法(同义)
        • ne():不等于比较
        • nlargest():最大的N个值
        • notna():非缺失判断
        • notnull():非缺失(同义)
        • now():当前时间戳
        • nsmallest():最小的N个值
        • nunique():唯一值数量
        • parse():解析Excel工作表
        • pop():移除并返回列
        • pow():幂运算
        • qcut():分位数分箱
        • radd():反向加法
        • ravel():展平为一维数组
        • rdiv():反向除法
    • 八、快速索引
      • 方法快速索引
    • 九、参考资料

【pandas 公开成员统计】:共 41 个公开类,628 个公开方法,239 个公开属性

六、公开方法速查(按功能分类)

本部分继续列出公开方法详细条目。

equals():对象相等判断
Index.equals(self, other: 'object') -> 'bool'

归属:pandas.Index

说明:判断两个 Index 对象是否完全相等(包括值、名称、dtype)。

importpandasaspd idx1=pd.Index(["北京","上海","广州"],name="城市")idx2=pd.Index(["北京","上海","广州"],name="城市")idx3=pd.Index(["北京","上海","深圳"],name="城市")print("相同:",idx1.equals(idx2),"不同:",idx1.equals(idx3))# 输出: True False

eval():表达式计算
DataFrame.eval(self, expr: 'str', *, inplace: 'bool' = False, **kwargs) -> 'Any | None'

归属:pandas.DataFrame

说明:在 DataFrame 列上执行字符串表达式计算,比手动写列运算更简洁且支持多核加速。

importpandasaspd 商品表=pd.DataFrame({"单价":[100,200,50],"数量":[3,1,10]})商品表.eval("金额 = 单价 * 数量",inplace=True)print(商品表)# 输出:# 单价 数量 金额# 0 100 3 300# 1 200 1 200# 2 50 10 500

归属:pandas

说明:pandas 顶层 eval,支持对局部或全局变量的表达式求值。

importpandasaspd df=pd.DataFrame({"A":[1,2,3],"B":[4,5,6]})result=pd.eval("df.A + df.B")print(result.tolist())# 输出: [5, 7, 9]

factorize():因子编码
pd.factorize(values, sort: 'bool' = False, use_na_sentinel: 'bool' = True, size_hint: 'int | None' = None) -> 'tuple[np.ndarray, np.ndarray | Index]'

归属:pandas

说明:将字符串/分类值编码为整数标签和唯一值映射,适合替代 sklearn 的 LabelEncoder。

importpandasaspd 城市列表=["北京","上海","北京","广州","上海"]编码,唯一值=pd.factorize(城市列表)print("整数编码:",编码)# 输出: [0, 1, 0, 2, 1]print("唯一值:",唯一值.tolist())# 输出: ['北京', '上海', '广州']

floor():时间向下取整
DatetimeIndex.floor(self, *args, **kwargs)

归属:pandas.DatetimeIndex

说明:将 DatetimeIndex 中的时间向下对齐到指定频率(小时/天/周等)。

importpandasaspd 日期=pd.DatetimeIndex(["2026-05-28 15:45:30","2026-05-29 23:10:00"])print("以小时取整:",日期.floor("h").tolist())# 输出: [Timestamp('2026-05-28 15:00'), Timestamp('2026-05-29 23:00')]

归属:pandas.Timedelta

说明:将 Timedelta 向下取整到指定精度。

importpandasaspd td=pd.Timedelta("3 hours 45 minutes")print(td.floor("h"))# 输出: 0 days 03:00:00

归属:pandas.Timestamp

说明:将时间戳向下取整到指定频率。

importpandasaspd ts=pd.Timestamp("2026-05-28 15:45:30")print(ts.floor("h"))# 输出: 2026-05-28 15:00:00

floordiv():整除运算
DataFrame.floordiv(self, other, axis: 'Axis' = 'columns', level=None, fill_value=None) -> 'DataFrame'

归属:pandas.DataFrame

说明:对 DataFrame 逐元素执行整除//运算。

importpandasaspd df=pd.DataFrame({"总量":[100,250,333],"每组人数":[3,5,10]})df["组数"]=df["总量"].floordiv(df["每组人数"])print(df)# 输出:# 总量 每组人数 组数# 0 100 3 33# 1 250 5 50# 2 333 10 33

flush():刷新到磁盘
HDFStore.flush(self, fsync: 'bool' = False) -> 'None'

归属:pandas.HDFStore

说明:将 HDF5 存储中的缓冲区数据强制写入磁盘,适合断电或异常安全场景。

frompathlibimportPathimportpandasaspd 路径=Path("测试.h5")store=pd.HDFStore(路径,mode="w")store["data"]=pd.DataFrame({"x":[1,2]})store.flush(fsync=True)store.close()路径.unlink(missing_ok=True)

format():格式化输出
Index.format(self, name: 'bool' = False, formatter: 'Callable | None' = None, na_rep: 'str_t' = 'NaN') -> 'list[str_t]'

归属:pandas.Index

说明:将 Index 各元素转为格式化后的字符串列表,支持自定义格式化函数。

importpandasaspd 日期=pd.DatetimeIndex(["2026-05-28","2026-05-29"],name="日期")print(日期.format(formatter=lambdax:x.strftime("%Y/%m/%d")))# 输出: ['2026/05/28', '2026/05/29']

fromordinal():序数转时间戳
Timestamp.fromordinal(cls, ordinal, tz=None)

归属:pandas.Timestamp

说明:从 Python datetime 的序数(公历日序号)构造 Timestamp。

importpandasaspd ts=pd.Timestamp.fromordinal(738613)# 大约对应 2026-05-28print(ts)# 输出: 约 2026-05-28 00:00:00

fromtimestamp():秒数转时间戳
Timestamp.fromtimestamp(cls, ts, tz=None)

归属:pandas.Timestamp

说明:从 Unix 时间戳(秒级浮点数)构造 Timestamp。

importpandasaspd ts=pd.Timestamp.fromtimestamp(1700000000)print(ts)# 输出: 约 2023-11-15

ge():大于等于比较
DataFrame.ge(self, other, axis: 'Axis' = 'columns', level=None) -> 'DataFrame'

归属:pandas.DataFrame

说明:逐元素比较是否 >= 给定值,返回布尔 DataFrame。

importpandasaspd 成绩表=pd.DataFrame({"语文":[85,90,78],"数学":[88,92,80]})及格=成绩表.ge(80)print(及格)# 输出:# 语文 数学# 0 True True# 1 True True# 2 False True

归属:pandas.Series

说明:逐元素比较是否 >= 给定值。

importpandasaspd s=pd.Series([120,80,150],name="销售额")print(s.ge(100))# 输出:# 0 True# 1 False# 2 True

gt():大于比较
DataFrame.gt(self, other, axis: 'Axis' = 'columns', level=None) -> 'DataFrame'

归属:pandas.DataFrame

说明:逐元素比较是否 > 给定值。

importpandasaspd df=pd.DataFrame({"销量":[120,80,150]})print(df["销量"].gt(100).tolist())# 输出: [True, False, True]

holds_integer():是否存整数值
Index.holds_integer(self) -> 'bool'

归属:pandas.Index

说明:判断 Index 中存储的元素是否可无损转为整数。

importpandasaspd 浮点索引=pd.Index([1.0,2.0,3.0])整数索引=pd.Index([1,2,3])print("浮点存整数:",浮点索引.holds_integer(),"整数存整数:",整数索引.holds_integer())# 输出: True True

identical():严格相同判断
Index.identical(self, other) -> 'bool'

归属:pandas.Index

说明:判断两个 Index 是否从头到尾完全相同(比 equals 更严格,检查名称和属性)。

importpandasaspd idx1=pd.Index([1,2,3
http://www.jsqmd.com/news/904857/

相关文章:

  • Sora 2 AI主播生成全链路拆解:从提示词工程、语音驱动到唇形同步的7大关键技术突破
  • 基于DLP平台的手写数字分类——CPU到深度学习处理器的加速实践
  • 从零打造蓝牙遥控履带车:Arduino、3D打印与FPV系统全解析
  • 2025泉州除甲醛公司Top5深度测评:绿舒环保稳居榜首 - 绿舒环保母婴除甲醛
  • 2026年最值得关注的8款AI简历工具深度解析
  • 基于Raspberry Pi Pico W的Wi-Fi邮件报警系统设计与实现
  • 踩坑!JDK8u371 报 No appropriate protocol,加启动参数无效
  • 选择题专练数据库原理精选30题
  • 如何使用Legacy iOS Kit实现旧款iOS设备降级与越狱的完整指南
  • Arduino LED乒乓球游戏:从电路设计到状态机编程的嵌入式开发实践
  • 2.隐藏账户
  • crabc - api 开源项目更名 ApiGo,一站式 API 数据服务平台更新多项功能
  • 求职季必备!这7款AI简历工具,让你的简历匹配度飙升,效率翻倍!
  • 2026碑林区企业变更哪家好?西安碑林区优质财税机构TOP4测评 - 小柏云
  • Ubuntu 20.04 新手必看:刚装完系统,ifconfig和vim都用不了?5分钟搞定镜像源和常用工具安装
  • 老年人陪伴与护理智能体
  • 国内钢模板企业排行:5家实力厂商核心能力对比 - 奔跑123
  • 化龙附近拿证快的正规驾校盘点:5家机构客观对比 - 奔跑123
  • ZYZ28 2026.5.26 Round 记录
  • 专业开发者指南:使用pywencai高效获取同花顺问财金融数据
  • 对比自行维护与使用 Taotoken 聚合 API 的运维成本观感
  • Dism++:让Windows系统维护变得简单高效
  • 选择题专练数据库原理精选30题[答案]
  • 从零开始:用Harepacker复活版轻松打造你的MapleStory专属世界
  • Go语言跨平台数据库开发:实现跨平台数据持久化
  • Arduino模拟信号控制实战:电位器PWM调控电机与LED
  • 2026全国铝锭供应商盘点推荐 - 速递信息
  • 2026益阳高新区美容院实测测评 10家门店综合排名发布 - GrowthUME
  • Arduino智能垃圾桶实战:超声波感应与舵机控制全解析
  • 怎样高效捕获网页媒体资源:专业浏览器嗅探工具完整指南