找到关于编程的34423 篇文章

Python Pandas CategoricalIndex - 重新排序类别

AmitDiwan
更新于 2021年10月18日 07:04:54

368 次浏览

要重新排序类别,请在 Pandas 中使用 CategoricalIndex 的 reorder_categories() 方法。首先,导入所需的库 - import pandas as pd CategoricalIndex 只能采用有限的、通常是固定的可能值数量。使用“categories”参数设置类别的类别。使用“ordered”参数将类别视为有序的 - catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"]) 显示 CategoricalIndex - print("CategoricalIndex...", catIndex) 获取类别 - print("DisplayingCategories from CategoricalIndex...", catIndex.categories) 使用 reorder_categories() 重新排序类别。将类别的新顺序设置为参数 - print("CategoricalIndex after reordering categories...", catIndex.reorder_categories(["r", "s", "q", "p"])) 例子如下… 阅读更多

Python Pandas CategoricalIndex - 使用 lambda 重命名类别

AmitDiwan
更新于 2021年10月18日 07:02:14

139 次浏览

要使用 Lambda 重命名类别,请在 Pandas 中使用 CategoricalIndex 的 rename_categories() 方法。首先,导入所需的库 - import pandas as pd CategoricalIndex 只能采用有限的、通常是固定的可能值数量。使用“categories”参数设置类别的类别。使用“ordered”参数将类别视为有序的 - catIndex = pd.CategoricalIndex(["P", "Q", "R", "S", "P", "Q", "R", "S"], ordered=True, categories=["P", "Q", "R", "S"]) 显示 CategoricalIndex - print("CategoricalIndex...", catIndex) 使用 rename_categories() 重命名类别。设置新的类别,使用 lambda 并将所有类别设置为小写 - print("CategoricalIndex after renaming categories...", catIndex.rename_categories(lambda a: a.lower())) 例子如下… 阅读更多

Python Pandas CategoricalIndex - 使用类似字典的新类别重命名类别

AmitDiwan
更新于 2021年10月18日 06:50:12

96 次浏览

要使用类似字典的新类别重命名类别,请在 Pandas 中使用 CategoricalIndex 的 rename_categories() 方法。首先,导入所需的库 - import pandas as pd CategoricalIndex 只能采用有限的、通常是固定的可能值数量。使用“ordered”参数将类别视为有序的 - catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"]) 显示 CategoricalIndex - print("CategoricalIndex...", catIndex) 重命名类别。设置将替换旧类别的新类似字典的类别 print("CategoricalIndex after renaming categories...", catIndex.rename_categories({'p': 5, 'q': 10, 'r': 15, 's': 20})) 例子如下… 阅读更多

Python Pandas CategoricalIndex - 重命名类别

AmitDiwan
更新于 2021年10月18日 06:47:25

236 次浏览

要重命名类别,请在 Pandas 中使用 CategoricalIndex 的 rename_categories() 方法。首先,导入所需的库 - import pandas as pd CategoricalIndex 只能采用有限的、通常是固定的可能值数量。使用“categories”参数设置类别的类别。使用“ordered”参数将类别视为有序的 - catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"]) 重命名类别。设置将替换旧类别的新类别 - print("CategoricalIndex after renaming categories...", catIndex.rename_categories([5, 10, 15, 20])) 例子如下… 阅读更多

Python Pandas CategoricalIndex - 检查类别是否具有有序关系

AmitDiwan
更新于 2021年10月18日 06:44:28

75 次浏览

要检查类别是否具有有序关系,请使用 CategoricalIndex 的 ordered 属性。首先,导入所需的库 - import pandas as pd 使用“categories”参数设置类别的类别。使用“ordered”参数将类别视为有序的 - catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"]) 显示 Categorical Index - print("Categorical Index...", catIndex) 获取类别 - print("DisplayingCategories from CategoricalIndex...", catIndex.categories) 检查类别是否有序关系 - print("Does categories have ordered relationship...", catIndex.ordered) 例子如下… 阅读更多

Python Pandas CategoricalIndex - 获取此类别的类别

AmitDiwan
更新于 2021年10月18日 06:41:04

381 次浏览

要获取此类别的类别,请在 Pandas 中使用 CategoricalIndex 的 categories 属性。首先,导入所需的库 - import pandas as pd CategoricalIndex 只能采用有限的、通常是固定的可能值数量(类别)。使用“categories”参数设置类别的类别。使用“ordered”参数将类别视为有序的 - catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"]) 显示 Categorical Index - print("Categorical Index...", catIndex) 获取类别 - print("Displaying Categories from CategoricalIndex...", catIndex.categories) 例子如下… 阅读更多

Python Pandas CategoricalIndex - 获取此类别的类别代码

AmitDiwan
更新于 2021年10月18日 06:38:25

307 次浏览

要获取此类别的类别代码,请在 Pandas 中使用 CategoricalIndex 的 codes 属性。首先,导入所需的库 - import pandas as pd CategoricalIndex 只能采用有限的、通常是固定的可能值数量(类别)。使用“categories”参数设置类别的类别。使用“ordered”参数将类别视为有序的。代码是整数数组,它们是 categories 数组中实际值的位

C++程序:找出矩阵中元素和等于特定值的子矩阵个数

Arnab Chakraborty
更新于 2021年10月16日 12:08:35

229 次浏览

假设我们得到一个包含整数值的矩阵。我们必须找出矩阵中的子矩阵,其中矩阵的元素之和等于给定的目标和值。我们返回子矩阵的数量。因此,如果输入类似于 0 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1,目标值为 5,则输出为 3。元素之和等于 6 的子矩阵的数量为 2。为了解决这个问题,我们将遵循以下步骤 - n := mat 的大小 m := (如果 n 等于 0,则为 0,否则为 mat[0] 的大小) 如果 m > n,则 - 定义一个大小为… 阅读更多

C++程序:找出非零子矩阵的个数

Arnab Chakraborty
更新于 2021年10月16日 12:02:14

420 次浏览

假设我们得到一个只包含两个值(1 和 0)的矩阵。我们必须找出给定矩阵中包含全为 1 的子矩阵的数量。我们将值作为输出打印出来。因此,如果输入类似于 0 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1,则输出为 12。为了解决这个问题,我们将遵循以下步骤 - n := 矩阵的大小 m := matrix[0] 的大小 定义一个大小为:n+1 x m+1 的数组 add。对于初始化 i := 0,当 i < n 时,更新(增加 i),执行 - 对于初始化 j := 0,当 j < m 时,更新(增加 j),执行… 阅读更多

C++程序:找出连接每个笛卡尔坐标的最小成本

Arnab Chakraborty
更新于 2021年10月16日 11:53:51

197 次浏览

假设我们有一组二维笛卡尔坐标点 (x, y)。我们可以连接 (x0, y0) 和 (x1, y1),其成本为 |x0 - x1| + |y0 - y1|。如果允许我们连接任意数量的点,我们必须找到必要的最小成本,以便每一点都通过路径连接。因此,如果输入类似于 points = [[0, 0], [0, 2], [0, -2], [2, 0], [-2, 0], [2, 3], [2, -3]],则输出为 14,因为从 (0, 0) 到 (0, 2), (0, -2), (2, 0), (-2, 0) 的成本是 2,… 阅读更多

广告
© . All rights reserved.