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

九江建企业网站菏泽网站建设服务

九江建企业网站,菏泽网站建设服务,校园网登录入口,网站建设的简历目录 一、用法精讲 801、pandas.Categorical类 801-1、语法 801-2、参数 801-3、功能 801-4、返回值 801-5、说明 801-6、用法 801-6-1、数据准备 801-6-2、代码示例 801-6-3、结果输出 802、pandas.Categorical.from_codes方法 802-1、语法 802-2、参数 802-3、…

目录

一、用法精讲

801、pandas.Categorical类

801-1、语法

801-2、参数

801-3、功能

801-4、返回值

801-5、说明

801-6、用法

801-6-1、数据准备

801-6-2、代码示例

801-6-3、结果输出

802、pandas.Categorical.from_codes方法

802-1、语法

802-2、参数

802-3、功能

802-4、返回值

802-5、说明

802-6、用法

802-6-1、数据准备

802-6-2、代码示例

802-6-3、结果输出

803、pandas.Categorical.dtype属性

803-1、语法

803-2、参数

803-3、功能

803-4、返回值

803-5、说明

803-6、用法

803-6-1、数据准备

803-6-2、代码示例

803-6-3、结果输出

804、pandas.Categorical.categories属性

804-1、语法

804-2、参数

804-3、功能

804-4、返回值

804-5、说明

804-6、用法

804-6-1、数据准备

804-6-2、代码示例

804-6-3、结果输出

805、pandas.Categorical.ordered属性

805-1、语法

805-2、参数

805-3、功能

805-4、返回值

805-5、说明

805-6、用法

805-6-1、数据准备

805-6-2、代码示例

805-6-3、结果输出

二、推荐阅读

1、Python筑基之旅

2、Python函数之旅

3、Python算法之旅

4、Python魔法之旅

5、博客个人主页

一、用法精讲

801、pandas.Categorical
801-1、语法
# 801、pandas.Categorical类
class pandas.Categorical(values, categories=None, ordered=None, dtype=None, fastpath=_NoDefault.no_default, copy=True)
Represent a categorical variable in classic R / S-plus fashion.Categoricals can only take on a limited, and usually fixed, number of possible values (categories). In contrast to statistical categorical variables, a Categorical might have an order, but numerical operations (additions, divisions, …) are not possible.All values of the Categorical are either in categories or np.nan. Assigning values outside of categories will raise a ValueError. Order is defined by the order of the categories, not lexical order of the values.Parameters:
values
list-like
The values of the categorical. If categories are given, values not in categories will be replaced with NaN.categories
Index-like (unique), optional
The unique categories for this categorical. If not given, the categories are assumed to be the unique values of values (sorted, if possible, otherwise in the order in which they appear).ordered
bool, default False
Whether or not this categorical is treated as a ordered categorical. If True, the resulting categorical will be ordered. An ordered categorical respects, when sorted, the order of its categories attribute (which in turn is the categories argument, if provided).dtype
CategoricalDtype
An instance of CategoricalDtype to use for this categorical.Raises:
ValueError
If the categories do not validate.TypeError
If an explicit ordered=True is given but no categories and the values are not sortable.
801-2、参数

801-2-1、values(必须)array-like(如列表、numpy数组等),表示输入的值,通常是一个列表、数组或其他可迭代对象,其中的数据将被转换为分类类型。

801-2-2、categories(可选,默认值为None)array-like,定义分类的类别,可以是一个列表或数组,包含所有可能的类别。如果不指定,类别将从values中提取。如果categories的元素不包含在values中,仍可将其指定,但这些类别将被视为未出现类别。

801-2-3、ordered(可选,默认值为None)布尔值,指定类别是否有顺序,如果设为True,则可用来执行有序比较。

801-2-4、dtype(可选,默认值为None)CategoricalDtype或其他类型,指定类别的数据类型,可以通过设置此参数来自定义数据类型。

801-2-5、fastpath(可选)布尔值,如果设为True,将绕过一些验证和处理步骤,适用于已经知道数据是分类的情况。

801-2-6、copy(可选,默认值为True)布尔值,指定是否复制输入的数据,如果设为True,将创建values的副本。

801-3、功能
  • 内存效率: 使用分类数据可以显著降低内存消耗,特别是在处理重复类别的情况下。
  • 提高性能: 在数据分析中,分类数据的比较和处理速度通常比非分类数据快。
  • 易于操作: 提供诸如排序、分组等功能,可以方便地进行数据操作。
801-4、返回值

        返回一个Categorical对象,其中包含:

  • 分类值: 将values变量转换为指定的分类类型。
  • 类别信息: 所有定义的类别,包括用户提供的类别和从values中提取的类别。
  • 有序性信息: 指示类别是否有序的布尔值。
801-5、说明

        无

801-6、用法
801-6-1、数据准备
801-6-2、代码示例
# 801、pandas.Categorical类
import pandas as pd
# 创建一个分类类型数据
data = ['apple', 'banana', 'orange', 'banana', 'apple']
cat_data = pd.Categorical(data, categories=['apple', 'banana', 'orange'], ordered=True)
print(cat_data)
801-6-3、结果输出
# 801、pandas.Categorical类
# ['apple', 'banana', 'orange', 'banana', 'apple']
# Categories (3, object): ['apple' < 'banana' < 'orange']
802、pandas.Categorical.from_codes方法
802-1、语法
# 802、pandas.Categorical.from_codes方法
classmethod Categorical.from_codes(codes, categories=None, ordered=None, dtype=None, validate=True)
Make a Categorical type from codes and categories or dtype.This constructor is useful if you already have codes and categories/dtype and so do not need the (computation intensive) factorization step, which is usually done on the constructor.If your data does not follow this convention, please use the normal constructor.Parameters:
codesarray-like of int
An integer array, where each integer points to a category in categories or dtype.categories, or else is -1 for NaN.categoriesindex-like, optional
The categories for the categorical. Items need to be unique. If the categories are not given here, then they must be provided in dtype.orderedbool, optional
Whether or not this categorical is treated as an ordered categorical. If not given here or in dtype, the resulting categorical will be unordered.dtypeCategoricalDtype or “category”, optional
If CategoricalDtype, cannot be used together with categories or ordered.validatebool, default True
If True, validate that the codes are valid for the dtype. If False, don’t validate that the codes are valid. Be careful about skipping validation, as invalid codes can lead to severe problems, such as segfaults.New in version 2.1.0.Returns:
Categorical
802-2、参数

802-2-1、codes(必须)整数数组,表示每个数据点对应的类别编码。

802-2-2、categories(可选,默认值为None)指定类别的顺序,如果未提供,则从codes中推断。

802-2-3、ordered(可选,默认值为None)布尔值,指定分类是否有序。

802-2-4、dtype(可选,默认值为None)指定返回的Categorical对象的dtype。

802-2-5、validate(可选,默认值为True)布尔值,如果为True,会检查codes是否有效(即是否在[0, len(categories))范围内)。

802-3、功能

        用于从整数编码和类别创建Categorical对象,它提供了一种直接从编码创建分类数据的方式,而不是从原始数据转换。

802-4、返回值

        返回一个新的Categorical对象。

802-5、说明

        无

802-6、用法
802-6-1、数据准备
802-6-2、代码示例
# 802、pandas.Categorical.from_codes方法
import pandas as pd
codes = [0, 1, 2, 1, 0]
categories = ['apple', 'banana', 'orange']
cat = pd.Categorical.from_codes(codes, categories)
print(cat)
802-6-3、结果输出
# 802、pandas.Categorical.from_codes方法
# ['apple', 'banana', 'orange', 'banana', 'apple']
# Categories (3, object): ['apple', 'banana', 'orange']
803、pandas.Categorical.dtype属性
803-1、语法
# 803、pandas.Categorical.dtype属性
property Categorical.dtype
The CategoricalDtype for this instance.
803-2、参数

        无

803-3、功能

        用于获取或设置分类数据的类型信息。

803-4、返回值

        返回一个CategoricalDtype对象,表示该分类数据的类别及其是否有序的信息。

803-5、说明

        无

803-6、用法
803-6-1、数据准备
803-6-2、代码示例
# 803、pandas.Categorical.dtype属性
import pandas as pd
# 创建一个Categorical对象
cat = pd.Categorical(['apple', 'banana', 'apple'], categories=['apple', 'banana', 'orange'], ordered=True)
# 获取dtype属性
dtype_info = cat.dtype
print(dtype_info)
# 获取类别
print(dtype_info.categories)
# 检查是否有序
print(dtype_info.ordered)
803-6-3、结果输出
# 803、pandas.Categorical.dtype属性
# category
# Index(['apple', 'banana', 'orange'], dtype='object')
# True
804、pandas.Categorical.categories属性
804-1、语法
# 804、pandas.Categorical.categories属性
property Categorical.categories
The categories of this categorical.Setting assigns new values to each category (effectively a rename of each individual category).The assigned value has to be a list-like object. All items must be unique and the number of items in the new categories must be the same as the number of items in the old categories.Raises:
ValueError
If the new categories do not validate as categories or if the number of new categories is unequal the number of old categories.
804-2、参数

        无

804-3、功能

        提供一个包含分类数据的所有唯一类别的索引对象,该索引对象可以用来查看和操作分类数据中的类别。

804-4、返回值

        返回一个Index对象,其中包含分类数据中所有唯一的类别。

804-5、说明

        无

804-6、用法
804-6-1、数据准备
804-6-2、代码示例
# 804、pandas.Categorical.categories属性
import pandas as pd
# 创建一个分类数据
data = pd.Categorical(["a", "b", "c", "a", "b"])
# 获取分类的所有唯一类别
categories = data.categories
print(categories)
804-6-3、结果输出
# 804、pandas.Categorical.categories属性
# Index(['a', 'b', 'c'], dtype='object')
805、pandas.Categorical.ordered属性
805-1、语法
# 805、pandas.Categorical.ordered属性
property Categorical.ordered
Whether the categories have an ordered relationship.
805-2、参数

        无

805-3、功能

        用来指示是否将类别视为有序(即有顺序的分类)或无序(即没有顺序的分类)。

  • 如果ordered=True,则表示分类具有一定的顺序,例如“低”、“中”、“高”。
  • 如果ordered=False,则表示分类之间没有顺序关系,例如“红色”、“蓝色”、“绿色”。
805-4、返回值

        创建Categorical对象时,如果将ordered设置为True,则返回的对象将允许进行一些顺序相关的操作,比如比较、排序等,这种情况下,可以使用Categorical的内置方法进行排序和比较。

805-5、说明

        无

805-6、用法
805-6-1、数据准备
805-6-2、代码示例
# 805、pandas.Categorical.ordered属性
import pandas as pd
# 创建一个无序的分类数据
cat_unordered = pd.Categorical(['apple', 'banana', 'orange'], ordered=False)
print(cat_unordered)
# 创建一个有序的分类数据
cat_ordered = pd.Categorical(['low', 'medium', 'high'], ordered=True)
print(cat_ordered)
# 比较顺序
print(cat_ordered[1] > cat_ordered[0])
print(cat_ordered[0] < cat_ordered[2]) 
805-6-3、结果输出
# 805、pandas.Categorical.ordered属性
# ['apple', 'banana', 'orange']
# Categories (3, object): ['apple', 'banana', 'orange']
# ['low', 'medium', 'high']
# Categories (3, object): ['high' < 'low' < 'medium']
# True
# False

二、推荐阅读

1、Python筑基之旅
2、Python函数之旅
3、Python算法之旅
4、Python魔法之旅
5、博客个人主页
http://www.yayakq.cn/news/934593/

相关文章:

  • 网站后台开发深圳公司网站设计公司
  • 网站建设基本流程教学视频教程邢台快用网络科技有限公司
  • 无锡网站设计无锡网站建设做高端网站
  • 在线房屋建设设计网站品牌注册公司
  • 旅游网站建设的参考文献新手网络推广怎么干
  • 上海网站制作哪家好网站建设背景图片
  • 安阳企业建网站wordpress pcms
  • 定制化网站开发11网拍推广平台
  • 网站快照更新慢计算机专业是干什么的
  • 网站配色方案橙色专业网站设计发展前景
  • 网站开发的工作经验配资网站建设
  • 做博客网站怎么赚钱吗cms监控软件电脑版官方下载
  • 博客建站系统可以发外链的网站或平台有哪些
  • 网站建设衡水做网站推广的工作好吗
  • 威海做企业网站的公司做网站怎么收集资料
  • 哔哩哔哩网站4 3比例怎么做网站被别人域名绑定
  • 什么人需要网站建设淄博做网站的哪家最好
  • 网站 乱码阿里云做网站麻烦吗
  • 室内设计效果图360全景图抖音搜索排名优化
  • 查询类网站开发wordpress缓存删除了有什么后果
  • 怎么做网站底部文件建设网站需要了解些什么
  • 如何做网站后台管理系统洛阳设计公司官网
  • 中国联通网站备案管理系统哪些网站可以做店铺推广
  • 网站登录窗口怎么做世纪购网站开发招聘
  • 网站优化公司谷歌优化网站服务器速度
  • 微信企业微网站上海注册公司多久
  • 个人简历模板网站凡科建站骗子
  • 网站顶部地图代码怎么做三亚最新发布
  • 网站建设中首页模板网络代写
  • 网站模板 扁平化十大室内设计师排名