企业网站托管方案内容具体有哪些,网站构思,北京外贸网站建设,网站建设公司上海做网站公司哪家好目录
一、用法精讲
961、pandas.IntervalIndex.mid属性
961-1、语法
961-2、参数
961-3、功能
961-4、返回值
961-5、说明
961-6、用法
961-6-1、数据准备
961-6-2、代码示例
961-6-3、结果输出
962、pandas.IntervalIndex.length属性
962-1、语法
962-2、参数
…目录
一、用法精讲
961、pandas.IntervalIndex.mid属性
961-1、语法
961-2、参数
961-3、功能
961-4、返回值
961-5、说明
961-6、用法
961-6-1、数据准备
961-6-2、代码示例
961-6-3、结果输出
962、pandas.IntervalIndex.length属性
962-1、语法
962-2、参数
962-3、功能
962-4、返回值
962-5、说明
962-6、用法
962-6-1、数据准备
962-6-2、代码示例
962-6-3、结果输出
963、pandas.IntervalIndex.get_loc方法
963-1、语法
963-2、参数
963-3、功能
963-4、返回值
963-5、说明
963-6、用法
963-6-1、数据准备
963-6-2、代码示例
963-6-3、结果输出
964、pandas.IntervalIndex.get_indexer方法
964-1、语法
964-2、参数
964-3、功能
964-4、返回值
964-5、说明
964-6、用法
964-6-1、数据准备
964-6-2、代码示例
964-6-3、结果输出
965、pandas.MultiIndex类
965-1、语法
965-2、参数
965-3、功能
965-4、返回值
965-5、说明
965-6、用法
965-6-1、数据准备
965-6-2、代码示例
965-6-3、结果输出
二、推荐阅读
1、Python筑基之旅
2、Python函数之旅
3、Python算法之旅
4、Python魔法之旅
5、博客个人主页 一、用法精讲
961、pandas.IntervalIndex.mid属性
961-1、语法
# 961、pandas.IntervalIndex.mid属性
pandas.IntervalIndex.mid
961-2、参数 无
961-3、功能 用于返回IntervalIndex中每个区间的中点该属性对每个在IntervalIndex中定义的区间计算中间值结果是一个Float64Index或Int64Index具体取决于区间的类型。
961-4、返回值 返回值是一个Float64Index它包含每个区间的中间值这些中间值是通过计算每个区间的下限和上限之间的平均值得到的。具体来说对于每个区间[a, b]中点计算公式为(a b) / 2。
961-5、说明 无
961-6、用法
961-6-1、数据准备
无
961-6-2、代码示例
# 961、pandas.IntervalIndex.mid属性
import pandas as pd
# 创建一个IntervalIndex
interval_index pd.IntervalIndex.from_tuples([(1, 3), (4, 6), (7, 9)])
# 获取每个区间的中点
mid_points interval_index.mid
print(mid_points)
961-6-3、结果输出
# 961、pandas.IntervalIndex.mid属性
# Index([2.0, 5.0, 8.0], dtypefloat64)
962、pandas.IntervalIndex.length属性
962-1、语法
# 962、pandas.IntervalIndex.length属性
pandas.IntervalIndex.length
962-2、参数 无
962-3、功能 计算IntervalIndex中每个区间的长度。
962-4、返回值 返回一个Int64Index对象包含每个区间的长度。
962-5、说明 无
962-6、用法
962-6-1、数据准备
无
962-6-2、代码示例
# 962、pandas.IntervalIndex.length属性
import pandas as pd
# 创建一个IntervalIndex
intervals pd.IntervalIndex.from_tuples([(0, 1), (1, 3), (3, 5)])
# 计算区间的长度
lengths intervals.length
print(lengths)
962-6-3、结果输出
# 962、pandas.IntervalIndex.length属性
# Index([1, 2, 2], dtypeint64)
963、pandas.IntervalIndex.get_loc方法
963-1、语法
# 963、pandas.IntervalIndex.get_loc方法
pandas.IntervalIndex.get_loc(key)
Get integer location, slice or boolean mask for requested label.Parameters:
key
label
Returns:
int if unique index, slice if monotonic index, else mask
963-2、参数
963-2-1、key(必须)表示要查找的区间可以是一个Interval对象。
963-3、功能 用于查找指定的区间在IntervalIndex中的位置(索引)该方法可以帮助你快速确定某个区间是否存在于IntervalIndex中以及它的位置。
963-4、返回值 返回指定区间的整数索引如果区间不存在则会抛出KeyError。
963-5、说明 无
963-6、用法
963-6-1、数据准备
无
963-6-2、代码示例
# 963、pandas.IntervalIndex.get_loc方法
import pandas as pd
# 创建一个IntervalIndex
intervals pd.IntervalIndex.from_tuples([(0, 1), (1, 3), (3, 5)])
# 使用get_loc查找区间的位置
loc1 intervals.get_loc(pd.Interval(0, 1))
loc2 intervals.get_loc(pd.Interval(1, 3))
print(loc1)
print(loc2)
963-6-3、结果输出
# 963、pandas.IntervalIndex.get_loc方法
# 0
# 1
964、pandas.IntervalIndex.get_indexer方法
964-1、语法
# 964、pandas.IntervalIndex.get_indexer方法
pandas.IntervalIndex.get_indexer(target, methodNone, limitNone, toleranceNone)
Compute indexer and mask for new index given the current index.The indexer should be then used as an input to ndarray.take to align the current data to the new index.Parameters:
targetIndex
method{None, ‘pad’/’ffill’, ‘backfill’/’bfill’, ‘nearest’}, optional
default: exact matches only.pad / ffill: find the PREVIOUS index value if no exact match.backfill / bfill: use NEXT index value if no exact matchnearest: use the NEAREST index value if no exact match. Tied distances are broken by preferring the larger index value.limitint, optional
Maximum number of consecutive labels in target to match for inexact matches.toleranceoptional
Maximum distance between original and new labels for inexact matches. The values of the index at the matching locations must satisfy the equation abs(index[indexer] - target) tolerance.Tolerance may be a scalar value, which applies the same tolerance to all values, or list-like, which applies variable tolerance per element. List-like includes list, tuple, array, Series, and must be the same size as the index and its dtype must exactly match the index’s type.Returns:
np.ndarray[np.intp]
Integers from 0 to n - 1 indicating that the index at these positions matches the corresponding target values. Missing values in the target are marked by -1.NotesReturns -1 for unmatched values, for further explanation see the example below.
964-2、参数
964-2-1、target(必须)array-like一个包含要查找的值的数组或序列这些值可以是区间的边界或其他数值。
964-2-2、method(可选默认值为None)str指定查找方法可选值包括
pad或ffill查找第一个小于或等于目标值的区间(向前查找)。backfill或bfill查找第一个大于目标值的区间(向后查找)。
964-2-3、limit(可选默认值为None)int限制结果中可以返回的匹配数量如果设置了这个参数返回的位置索引将受到限制。
964-2-4、tolerance(可选默认值为None)array-like指定容忍度以控制可以接受的值范围如果提供了这个参数则只有在区间边界内的值才会被视为匹配。
964-3、功能 检索target中每个元素在IntervalIndex中的索引位置它能够处理不同的查找策略(如精确匹配、向前查找和向后查找)。
964-4、返回值 返回一个一维的NumPy数组其中包含target中每个值在IntervalIndex中的对应索引如果某个值在区间中没有找到则返回-1。
964-5、说明 无
964-6、用法
964-6-1、数据准备
无
964-6-2、代码示例
# 964、pandas.IntervalIndex.get_indexer方法
import pandas as pd
index pd.Index([c, a, b])
arr1 index.get_indexer([a, b, x])
print(arr1)
964-6-3、结果输出
# 964、pandas.IntervalIndex.get_indexer方法
# [ 1 2 -1]
965、pandas.MultiIndex类
965-1、语法
# 965、pandas.MultiIndex类
class pandas.MultiIndex(levelsNone, codesNone, sortorderNone, namesNone, dtypeNone, copyFalse, nameNone, verify_integrityTrue)
A multi-level, or hierarchical, index object for pandas objects.Parameters:
levels
sequence of arrays
The unique labels for each level.codes
sequence of arrays
Integers for each level designating which label at each location.sortorder
optional int
Level of sortedness (must be lexicographically sorted by that level).names
optional sequence of objects
Names for each of the index levels. (name is accepted for compat).copy
bool, default False
Copy the meta-data.verify_integrity
bool, default True
Check that the levels/codes are consistent and valid.See alsoMultiIndex.from_arrays
Convert list of arrays to MultiIndex.MultiIndex.from_product
Create a MultiIndex from the cartesian product of iterables.MultiIndex.from_tuples
Convert list of tuples to a MultiIndex.MultiIndex.from_frame
Make a MultiIndex from a DataFrame.Index
The base pandas Index type.NotesSee the user guide for more.
965-2、参数
965-2-1、levels(可选默认值为None)list一个包含多个层级(levels)列表的集合每个层级包含该层的所有唯一值这些值在创建MultiIndex时定义了每一层的内容。
965-2-2、codes(可选默认值为None)list一个包含整数列表的集合表示各个层级的索引位置长度应与levels参数对应指定每个层级中对应值的位置。
965-2-3、sortorder(可选默认值为None)int指定索引的排序顺序可以是一个整数表示根据哪个层级进行排序。
965-2-4、names(可选默认值为None)list为MultiIndex的每一层级指定名称可以帮助在访问或操作数据时提高可读性默认情况下层级没有名称。
965-2-5、dtype(可选默认值为None)数据类型指定索引的数据类型默认情况下会根据提供的数据和层级自动推断。
965-2-6、copy(可选默认值为False)bool是否复制输入数据默认值为False如果为True将强制复制数据。
965-2-7、name(可选默认值为None)string为整个索引设置一个通用名称(单一名称)当MultiIndex作为某一列的索引时会用到。
965-2-8、verify_integrity(可选默认值为True)bool是否验证数组的完整性确保不含有重复的条目。
965-3、功能 支持多重层级索引允许在同一数据结构中组织更多的层次信息对于处理复杂的数据如时间序列或分组数据特别有用。
965-4、返回值 返回一个pandas.MultiIndex对象可以将其直接用于pandas的DataFrame或Series中作为索引其提供的方法和属性使得对多层结构数据的操作非常灵活和高效包括切片、合并、重设索引等。
965-5、说明 无
965-6、用法
965-6-1、数据准备
无
965-6-2、代码示例
# 965、pandas.MultiIndex类
import pandas as pd
# 创建多个层级的索引
levels [[A, B], [1, 2]]
codes [[0, 0, 1, 1], [0, 1, 0, 1]] # A1, A2, B1, B2
# 创建MultiIndex
multi_index pd.MultiIndex(levelslevels, codescodes, names[Letter, Number])
# 创建一个DataFrame并使用MultiIndex
data {Value: [10, 20, 30, 40]}
df pd.DataFrame(data, indexmulti_index)
# 显示DataFrame
print(初始DataFrame:)
print(df)
# 选取A的所有数据
print(\n选择A的数据:)
print(df.loc[A])
# 选择特定层级的值例如B和1
print(\n选择B1的数据:)
print(df.loc[(B, 1)])
# 重设索引
df_reset df.reset_index()
print(\n重设索引后的DataFrame:)
print(df_reset)
# 通过层级进行分组并计算均值
grouped df.groupby(levelLetter).mean()
print(\n按字母分组计算均值:)
print(grouped)
965-6-3、结果输出
# 965、pandas.MultiIndex类
# 初始DataFrame:
# Value
# Letter Number
# A 1 10
# 2 20
# B 1 30
# 2 40
#
# 选择A的数据:
# Value
# Number
# 1 10
# 2 20
#
# 选择B1的数据:
# Value 30
# Name: (B, 1), dtype: int64
#
# 重设索引后的DataFrame:
# Letter Number Value
# 0 A 1 10
# 1 A 2 20
# 2 B 1 30
# 3 B 2 40
#
# 按字母分组计算均值:
# Value
# Letter
# A 15.0
# B 35.0
二、推荐阅读
1、Python筑基之旅
2、Python函数之旅
3、Python算法之旅
4、Python魔法之旅
5、博客个人主页 文章转载自: http://www.morning.smkxm.cn.gov.cn.smkxm.cn http://www.morning.xfjwm.cn.gov.cn.xfjwm.cn http://www.morning.jfqpc.cn.gov.cn.jfqpc.cn http://www.morning.cczrw.cn.gov.cn.cczrw.cn http://www.morning.dtlqc.cn.gov.cn.dtlqc.cn http://www.morning.jfqqs.cn.gov.cn.jfqqs.cn http://www.morning.yzygj.cn.gov.cn.yzygj.cn http://www.morning.gtnyq.cn.gov.cn.gtnyq.cn http://www.morning.qrhh.cn.gov.cn.qrhh.cn http://www.morning.clyhq.cn.gov.cn.clyhq.cn http://www.morning.jwpcj.cn.gov.cn.jwpcj.cn http://www.morning.srckl.cn.gov.cn.srckl.cn http://www.morning.lcxdm.cn.gov.cn.lcxdm.cn http://www.morning.smfbw.cn.gov.cn.smfbw.cn http://www.morning.yfmxn.cn.gov.cn.yfmxn.cn http://www.morning.jzxqj.cn.gov.cn.jzxqj.cn http://www.morning.czxrg.cn.gov.cn.czxrg.cn http://www.morning.gcdzp.cn.gov.cn.gcdzp.cn http://www.morning.pcqdf.cn.gov.cn.pcqdf.cn http://www.morning.jlthz.cn.gov.cn.jlthz.cn http://www.morning.jbblf.cn.gov.cn.jbblf.cn http://www.morning.gychx.cn.gov.cn.gychx.cn http://www.morning.xgbq.cn.gov.cn.xgbq.cn http://www.morning.fqzz3.cn.gov.cn.fqzz3.cn http://www.morning.phlwj.cn.gov.cn.phlwj.cn http://www.morning.wtnwf.cn.gov.cn.wtnwf.cn http://www.morning.rfhmb.cn.gov.cn.rfhmb.cn http://www.morning.ljcjc.cn.gov.cn.ljcjc.cn http://www.morning.kpwdt.cn.gov.cn.kpwdt.cn http://www.morning.qmzhy.cn.gov.cn.qmzhy.cn http://www.morning.tgyqq.cn.gov.cn.tgyqq.cn http://www.morning.lsbjj.cn.gov.cn.lsbjj.cn http://www.morning.snccl.cn.gov.cn.snccl.cn http://www.morning.nptls.cn.gov.cn.nptls.cn http://www.morning.tjwlp.cn.gov.cn.tjwlp.cn http://www.morning.pjtnk.cn.gov.cn.pjtnk.cn http://www.morning.mbrbg.cn.gov.cn.mbrbg.cn http://www.morning.fmqw.cn.gov.cn.fmqw.cn http://www.morning.xfwnk.cn.gov.cn.xfwnk.cn http://www.morning.pbtdr.cn.gov.cn.pbtdr.cn http://www.morning.qphcq.cn.gov.cn.qphcq.cn http://www.morning.taojava.cn.gov.cn.taojava.cn http://www.morning.wlsrd.cn.gov.cn.wlsrd.cn http://www.morning.fchkc.cn.gov.cn.fchkc.cn http://www.morning.xnrgb.cn.gov.cn.xnrgb.cn http://www.morning.kkjlz.cn.gov.cn.kkjlz.cn http://www.morning.krhkb.cn.gov.cn.krhkb.cn http://www.morning.dndk.cn.gov.cn.dndk.cn http://www.morning.qjldz.cn.gov.cn.qjldz.cn http://www.morning.ppdr.cn.gov.cn.ppdr.cn http://www.morning.qxlyf.cn.gov.cn.qxlyf.cn http://www.morning.ngpdk.cn.gov.cn.ngpdk.cn http://www.morning.fpxsd.cn.gov.cn.fpxsd.cn http://www.morning.pzqnj.cn.gov.cn.pzqnj.cn http://www.morning.qtzwh.cn.gov.cn.qtzwh.cn http://www.morning.muzishu.com.gov.cn.muzishu.com http://www.morning.gyzfp.cn.gov.cn.gyzfp.cn http://www.morning.trtxt.cn.gov.cn.trtxt.cn http://www.morning.wnkqt.cn.gov.cn.wnkqt.cn http://www.morning.pmwhj.cn.gov.cn.pmwhj.cn http://www.morning.fbbpj.cn.gov.cn.fbbpj.cn http://www.morning.yskhj.cn.gov.cn.yskhj.cn http://www.morning.hxbjt.cn.gov.cn.hxbjt.cn http://www.morning.gfnsh.cn.gov.cn.gfnsh.cn http://www.morning.yxyyp.cn.gov.cn.yxyyp.cn http://www.morning.mlhfr.cn.gov.cn.mlhfr.cn http://www.morning.bwdnx.cn.gov.cn.bwdnx.cn http://www.morning.pfbx.cn.gov.cn.pfbx.cn http://www.morning.ktmbr.cn.gov.cn.ktmbr.cn http://www.morning.pmmrb.cn.gov.cn.pmmrb.cn http://www.morning.ggtkk.cn.gov.cn.ggtkk.cn http://www.morning.rlxg.cn.gov.cn.rlxg.cn http://www.morning.wxfjx.cn.gov.cn.wxfjx.cn http://www.morning.yfzld.cn.gov.cn.yfzld.cn http://www.morning.jbmbj.cn.gov.cn.jbmbj.cn http://www.morning.jwsrp.cn.gov.cn.jwsrp.cn http://www.morning.tqxtx.cn.gov.cn.tqxtx.cn http://www.morning.whclz.cn.gov.cn.whclz.cn http://www.morning.srckl.cn.gov.cn.srckl.cn http://www.morning.lwtld.cn.gov.cn.lwtld.cn