python Series api用法方法全解
文章目录
Series
构造函数
Series([data, index, dtype, name, copy, ...])
带有轴标签的一维ndarray(包括时间序列)。
属性
属性 | 描述 |
---|---|
Axes | |
Series.index | Series的索引(轴标签)。 |
Series.array | 该Series或Index的ExtensionArray支持的数据。 |
Series.values | 根据dtype返回作为ndarray或类似ndarray的Series。 |
Series.dtype | 返回底层数据的dtype对象。 |
Series.shape | 返回底层数据的形状的元组。 |
Series.nbytes | 返回底层数据的字节数。 |
Series.ndim | 底层数据的维度数,根据定义为1。 |
Series.size | 返回底层数据的元素数。 |
Series.T | 返回转置,根据定义是自身。 |
Series.memory_usage([index, deep]) | 返回Series的内存使用情况。 |
Series.hasnans | 如果存在任何NaN,则返回True。 |
Series.empty | 指示Series/DataFrame是否为空。 |
Series.dtypes | 返回底层数据的dtype对象。 |
Series.name | 返回Series的名称。 |
Series.flags | 获取与此pandas对象关联的属性。 |
Series.set_flags(*[, copy, …]) | 返回具有更新标志的新对象。 |
Conversion
方法名 | 描述 |
---|---|
Series.astype(dtype[, copy, errors]) | 将pandas对象转换为指定的dtype数据类型。 |
Series.convert_dtypes([infer_objects, …]) | 使用支持pd.NA的数据类型,将列转换为最佳可能的数据类型。 |
Series.infer_objects([copy]) | 尝试推断对象列的更好数据类型。 |
Series.copy([deep]) | 复制该对象的索引和数据。 |
Series.bool() | (已弃用)返回单个元素Series或DataFrame的布尔值。 |
Series.to_numpy([dtype, copy, na_value]) | 返回表示该Series或Index中的值的NumPy ndarray。 |
Series.to_period([freq, copy]) | 将Series从DatetimeIndex转换为PeriodIndex。 |
Series.to_timestamp([freq, how, copy]) | 转换为Timestamps的DatetimeIndex,位于时间段的开头。 |
Series.to_list() | 返回值的列表。 |
Series.array([dtype]) | 以NumPy数组的形式返回值。 |
索引和迭代
方法名 | 描述 |
---|---|
Series.get(key[, default]) | 获取给定键(例如:DataFrame列)对应的对象项。 |
Series.at | 访问行/列标签对应的单个值。 |
Series.iat | 按整数位置访问行/列对应的单个值。 |
Series.loc | 按标签或布尔数组访问一组行和列。 |
Series.iloc | 基于纯整数位置进行索引,以根据位置选择。 |
Series.iter() | 返回值的迭代器。 |
Series.items() | 惰性地遍历(索引,值)元组。 |
Series.keys() | 返回索引的别名。 |
Series.pop(item) | 返回项并从系列中删除。 |
Series.item() | 以Python标量的形式返回底层数据的第一个元素。 |
Series.xs(key[, axis, level, drop_level]) | 从Series/DataFrame返回交叉部分。 |
更多关于 .at、.iat、.loc 和 .iloc 的信息,请参阅索引文档。 |
二元操作符函数
方法名 | 描述 |
---|---|
Series.add(other[, level, fill_value, axis]) | 返回系列和其他系列相加的结果,逐元素操作(二元操作符 add)。 |
Series.sub(other[, level, fill_value, axis]) | 返回系列和其他系列相减的结果,逐元素操作(二元操作符 sub)。 |
Series.mul(other[, level, fill_value, axis]) | 返回系列和其他系列相乘的结果,逐元素操作(二元操作符 mul)。 |
Series.div(other[, level, fill_value, axis]) | 返回系列和其他系列相除的结果,逐元素操作(二元操作符 truediv)。 |
Series.truediv(other[, level, fill_value, axis]) | 返回系列和其他系列相除的结果,逐元素操作(二元操作符 truediv)。 |
Series.floordiv(other[, level, fill_value, axis]) | 返回系列和其他系列整除的结果,逐元素操作(二元操作符 floordiv)。 |
Series.mod(other[, level, fill_value, axis]) | 返回系列和其他系列取模的结果,逐元素操作(二元操作符 mod)。 |
Series.pow(other[, level, fill_value, axis]) | 返回系列和其他系列幂次方的结果,逐元素操作(二元操作符 pow)。 |
Series.radd(other[, level, fill_value, axis]) | 返回其他系列和系列相加的结果,逐元素操作(二元操作符 radd)。 |
Series.rsub(other[, level, fill_value, axis]) | 返回其他系列和系列相减的结果,逐元素操作(二元操作符 rsub)。 |
Series.rmul(other[, level, fill_value, axis]) | 返回其他系列和系列相乘的结果,逐元素操作(二元操作符 rmul)。 |
Series.rdiv(other[, level, fill_value, axis]) | 返回其他系列和系列相除的结果,逐元素操作(二元操作符 rtruediv)。 |
Series.rtruediv(other[, level, fill_value, axis]) | 返回其他系列和系列相除的结果,逐元素操作(二元操作符 rtruediv)。 |
Series.rfloordiv(other[, level, fill_value, …]) | 返回其他系列和系列整除的结果,逐元素操作(二元操作符 rfloordiv)。 |
Series.rmod(other[, level, fill_value, axis]) | 返回其他系列和系列取模的结果,逐元素操作(二元操作符 rmod)。 |
Series.rpow(other[, level, fill_value, axis]) | 返回其他系列和系列幂次方的结果,逐元素操作(二元操作符 rpow)。 |
Series.combine(other, func[, fill_value]) | 根据func将Series与Series或标量组合。 |
Series.combine_first(other) | 使用“other”中相同位置的值更新空元素。 |
Series.round([decimals]) | 将Series中的每个值四舍五入到给定的小数位数。 |
Series.lt(other[, level, fill_value, axis]) | 返回系列和其他系列的逐元素小于比较结果(二元操作符 lt)。 |
Series.gt(other[, level, fill_value, axis]) | 返回系列和其他系列的逐元素大于比较结果(二元操作符 gt)。 |
Series.le(other[, level, fill_value, axis]) | 返回系列和其他系列的逐元素小于等于比较结果(二元操作符 le)。 |
Series.ge(other[, level, fill_value, axis]) | 返回系列和其他系列的逐元素大于等于比较结果(二元操作符 ge)。 |
Series.ne(other[, level, fill_value, axis]) | 返回系列和其他系列的逐元素不等于比较结果(二元操作符 ne)。 |
Series.eq(other[, level, fill_value, axis]) | 返回系列和其他系列的逐元素等于比较结果(二元操作符 eq)。 |
Series.product([axis, skipna, numeric_only, …]) | 返回请求轴上值的乘积。 |
Series.dot(other) | 计算Series与其他列之间的点积。 |
函数应用,GroupBy和窗口
方法名 | 描述 |
---|---|
Series.apply(func[, convert_dtype, args, by_row]) | 对Series的值应用函数。 |
Series.agg([func, axis]) | 使用一个或多个操作在指定的轴上进行聚合。 |
Series.aggregate([func, axis]) | 使用一个或多个操作在指定的轴上进行聚合。 |
Series.transform(func[, axis]) | 在自身上调用func,生成与self具有相同轴形状的Series。 |
Series.map(arg[, na_action]) | 根据输入映射或函数对Series的值进行映射。 |
Series.groupby([by, axis, level, as_index, …]) | 使用映射器或一系列列进行分组。 |
Series.rolling(window[, min_periods, …]) | 提供滚动窗口计算。 |
Series.expanding([min_periods, axis, method]) | 提供扩展窗口计算。 |
Series.ewm([com, span, halflife, alpha, …]) | 提供指数加权(EW)计算。 |
Series.pipe(func, *args, **kwargs) | 应用期望Series或DataFrames的可链式函数。 |
计算/描述性统计
方法名 | 描述 |
---|---|
Series.abs() | 返回每个元素的绝对值的Series/DataFrame。 |
Series.all([axis, bool_only, skipna]) | 返回所有元素是否都为True,可能沿轴进行计算。 |
Series.any(*[, axis, bool_only, skipna]) | 返回任何一个元素是否为True,可能沿轴进行计算。 |
Series.autocorr([lag]) | 计算滞后N的自相关性。 |
Series.between(left, right[, inclusive]) | 返回等价于left <= series <= right的布尔Series。 |
Series.clip([lower, upper, axis, inplace]) | 在输入阈值处修剪值。 |
Series.corr(other[, method, min_periods]) | 计算与其他Series的相关性,排除缺失值。 |
Series.count() | 返回Series中非NA/null观测值的数量。 |
Series.cov(other[, min_periods, ddof]) | 计算与Series的协方差,排除缺失值。 |
Series.cummax([axis, skipna]) | 返回沿DataFrame或Series轴的累积最大值。 |
Series.cummin([axis, skipna]) | 返回沿DataFrame或Series轴的累积最小值。 |
Series.cumprod([axis, skipna]) | 返回沿DataFrame或Series轴的累积乘积。 |
Series.cumsum([axis, skipna]) | 返回沿DataFrame或Series轴的累积和。 |
Series.describe([percentiles, include, exclude]) | 生成描述性统计信息。 |
Series.diff([periods]) | 计算元素的第一差分。 |
Series.factorize([sort, use_na_sentinel]) | 将对象编码为枚举类型或分类变量。 |
Series.kurt([axis, skipna, numeric_only]) | 计算请求轴上的无偏峰度。 |
Series.max([axis, skipna, numeric_only]) | 返回请求轴上的最大值。 |
Series.mean([axis, skipna, numeric_only]) | 返回请求轴上的平均值。 |
Series.median([axis, skipna, numeric_only]) | 返回请求轴上的中位数。 |
Series.min([axis, skipna, numeric_only]) | 返回请求轴上的最小值。 |
Series.mode([dropna]) | 返回Series的众数。 |
Series.nlargest([n, keep]) | 返回最大的n个元素。 |
Series.nsmallest([n, keep]) | 返回最小的n个元素。 |
Series.pct_change([periods, fill_method, …]) | 当前元素与前一个元素之间的百分比变化。 |
Series.prod([axis, skipna, numeric_only, …]) | 返回请求轴上的值的乘积。 |
Series.quantile([q, interpolation]) | 返回给定分位数处的值。 |
Series.rank([axis, method, numeric_only, …]) | 在轴上计算数值数据的排名(1到n)。 |
Series.sem([axis, skipna, ddof, numeric_only]) | 返回请求轴上的无偏标准误差。 |
Series.skew([axis, skipna, numeric_only]) | 返回请求轴上的无偏偏斜度。 |
Series.std([axis, skipna, ddof, numeric_only]) | 返回请求轴上的样本标准差。 |
Series.sum([axis, skipna, numeric_only, …]) | 返回请求轴上的值的总和。 |
Series.var([axis, skipna, ddof, numeric_only]) | 返回请求轴上的无偏方差。 |
Series.kurtosis([axis, skipna, numeric_only]) | 计算请求轴上的无偏峰度。 |
Series.unique() | 返回Series对象的唯一值。 |
Series.nunique([dropna]) | 返回对象中的唯一元素数量。 |
Series.is_unique | 如果对象中的值是唯一的,则返回布尔值。 |
Series.is_monotonic_increasing | 如果对象中的值是单调递增的,则返回布尔值。 |
Series.is_monotonic_decreasing | 如果对象中的值是单调递减的,则返回布尔值。 |
Series.value_counts([normalize, sort, …]) | 返回包含唯一值计数的Series。 |
重新索引/选择/标签操作
方法名 | 描述 |
---|---|
Series.align(other[, join, axis, level, …]) | 使用指定的连接方法在它们的轴上对两个对象进行对齐。 |
Series.drop([labels, axis, index, columns, …]) | 返回删除指定索引标签的Series。 |
Series.droplevel(level[, axis]) | 返回删除请求的索引/列级别的Series / DataFrame。 |
Series.drop_duplicates(*[, keep, inplace, …]) | 返回删除重复值的Series。 |
Series.duplicated([keep]) | 指示Series中是否存在重复的值。 |
Series.equals(other) | 测试两个对象是否包含相同的元素。 |
Series.first(offset) | 根据日期偏移量选择时间序列数据的初始时期。 |
Series.head([n]) | 返回前n行。 |
Series.idxmax([axis, skipna]) | 返回最大值的行标签。 |
Series.idxmin([axis, skipna]) | 返回最小值的行标签。 |
Series.isin(values) | 检查Series中的元素是否包含在values中。 |
Series.last(offset) | 根据日期偏移量选择时间序列数据的最后时期。 |
Series.reindex([index, axis, method, copy, …]) | 将Series调整为具有新索引,可选填充逻辑。 |
Series.reindex_like(other[, method, copy, …]) | 返回与另一个对象具有相匹配索引的对象。 |
Series.rename([index, axis, copy, inplace, …]) | 更改Series的索引标签或名称。 |
Series.rename_axis([mapper, index, axis, …]) | 设置索引或列的轴的名称。 |
Series.reset_index([level, drop, name, …]) | 生成具有重置索引的新DataFrame或Series。 |
Series.sample([n, frac, replace, weights, …]) | 从对象的轴中返回随机样本项。 |
Series.set_axis(labels, *[, axis, copy]) | 将所需的索引分配给给定的轴。 |
Series.take(indices[, axis]) | 沿着轴返回给定位置索引处的元素。 |
Series.tail([n]) | 返回最后n行。 |
Series.truncate([before, after, axis, copy]) | 在某个索引值之前和之后截断Series或DataFrame。 |
Series.where(cond[, other, inplace, axis, level]) | 替换条件为False的值。 |
Series.mask(cond[, other, inplace, axis, level]) | 替换条件为True的值。 |
Series.add_prefix(prefix[, axis]) | 使用字符串前缀添加标签。 |
Series.add_suffix(suffix[, axis]) | 使用字符串后缀添加标签。 |
Series.filter([items, like, regex, axis]) | 根据指定的索引标签对数据帧的行或列进行子集操作。 |
缺失数据处理
方法名 | 描述 |
---|---|
Series.backfill(*[, axis, inplace, limit, …]) | (已弃用)使用下一个有效观测值填充NA/NaN值。 |
Series.bfill(*[, axis, inplace, limit, downcast]) | 使用下一个有效观测值填充NA/NaN值。 |
Series.dropna(*[, axis, inplace, how, …]) | 返回删除缺失值的新Series。 |
Series.ffill(*[, axis, inplace, limit, downcast]) | 将上一个有效观测值传播到下一个有效观测值以填充NA/NaN值。 |
Series.fillna([value, method, axis, …]) | 使用指定的方法填充NA/NaN值。 |
Series.interpolate([method, axis, limit, …]) | 使用插值方法填充NaN值。 |
Series.isna() | 检测缺失值。 |
Series.isnull() | Series.isnull是Series.isna的别名。 |
Series.notna() | 检测存在(非缺失)的值。 |
Series.notnull() | Series.notnull是Series.notna的别名。 |
Series.pad(*[, axis, inplace, limit, downcast]) | (已弃用)通过将上一个有效观测值传播到下一个有效观测值来填充NA/NaN值。 |
Series.replace([to_replace, value, inplace, …]) | 用给定值替换to_replace中的值。 |
重塑、排序
方法名 | 描述 |
---|---|
Series.argsort([axis, kind, order]) | 返回按Series值排序的整数索引。 |
Series.argmin([axis, skipna]) | 返回Series中最小值的位置。 |
Series.argmax([axis, skipna]) | 返回Series中最大值的位置。 |
Series.reorder_levels(order) | 使用指定的顺序重新排列索引级别。 |
Series.sort_values(*[, axis, ascending, …]) | 按值排序。 |
Series.sort_index(*[, axis, level, …]) | 按索引标签排序Series。 |
Series.swaplevel([i, j, copy]) | 在MultiIndex中交换级别i和j。 |
Series.unstack([level, fill_value, sort]) | 将具有MultiIndex的Series展开为DataFrame。 |
Series.explode([ignore_index]) | 将列表类型的每个元素转换为行。 |
Series.searchsorted(value[, side, sorter]) | 查找应插入元素以保持顺序的索引位置。 |
Series.ravel([order]) | 将底层数据扁平化为ndarray或ExtensionArray。 |
Series.repeat(repeats[, axis]) | 重复Series的元素。 |
Series.squeeze([axis]) | 将1维轴对象挤压成标量。 |
Series.view([dtype]) | 创建Series的新视图。 |
合并/比较/连接/合并
方法名 | 描述 |
---|---|
Series.compare(other[, align_axis, …]) | 将Series与另一个Series进行比较并显示差异。 |
Series.update(other) | 使用传递的Series值修改原始Series。 |
时间序列相关
方法名 | 描述 |
---|---|
Series.asfreq(freq[, method, how, …]) | 将时间序列转换为指定的频率。 |
Series.asof(where[, subset]) | 在where之前返回最后一行(没有NaN)的数据。 |
Series.shift([periods, freq, axis, …]) | 使用指定的周期数将索引向前或向后移动,可选使用时间频率。 |
Series.first_valid_index() | 返回第一个非NA值的索引,如果找不到非NA值,则返回None。 |
Series.last_valid_index() | 返回最后一个非NA值的索引,如果找不到非NA值,则返回None。 |
Series.resample(rule[, axis, closed, …]) | 重新采样时间序列数据。 |
Series.tz_convert(tz[, axis, level, copy]) | 将具有时区信息的轴转换为目标时区。 |
Series.tz_localize(tz[, axis, level, copy, …]) | 将tz-naive索引的Series或DataFrame本地化到目标时区。 |
Series.at_time(time[, asof, axis]) | 选择特定时间的值(例如:9:30AM)。 |
Series.between_time(start_time, end_time[, …]) | 选择某个时间范围内的值(例如:9:00-9:30 AM)。 |
访问器
pandas提供了特定于数据类型的方法,可以通过访问器进行访问。这些是在Series中仅适用于特定数据类型的单独命名空间。
数据类型 | 访问器 |
---|---|
Datetime, Timedelta, Period | dt |
String | str |
Categorical | cat |
Sparse | sparse |
日期时间属性
Series.dt可用于访问系列的值作为日期时间,并返回多个属性。可以像Series.dt.这样访问这些属性。
日期时间属性 | 描述 |
---|---|
Series.dt.date | 返回python datetime.date对象的numpy数组。 |
Series.dt.time | 返回datetime.time对象的numpy数组。 |
Series.dt.timetz | 返回带时区的datetime.time对象的numpy数组。 |
Series.dt.year | 日期的年份。 |
Series.dt.month | 月份(1月=1,12月=12)。 |
Series.dt.day | 日期的日。 |
Series.dt.hour | 日期的小时。 |
Series.dt.minute | 日期的分钟。 |
Series.dt.second | 日期的秒。 |
Series.dt.microsecond | 日期的微秒。 |
Series.dt.nanosecond | 日期的纳秒。 |
Series.dt.dayofweek | 星期几(星期一=0,星期天=6)。 |
Series.dt.day_of_week | 星期几(星期一=0,星期天=6)。 |
Series.dt.weekday | 星期几(星期一=0,星期天=6)。 |
Series.dt.dayofyear | 一年中的第几天。 |
Series.dt.day_of_year | 一年中的第几天。 |
Series.dt.days_in_month | 一个月中的天数。 |
Series.dt.quarter | 季度。 |
Series.dt.is_month_start | 指示日期是否为月的第一天。 |
Series.dt.is_month_end | 指示日期是否为月的最后一天。 |
Series.dt.is_quarter_start | 指示日期是否为季度的第一天。 |
Series.dt.is_quarter_end | 指示日期是否为季度的最后一天。 |
Series.dt.is_year_start | 指示日期是否为年的第一天。 |
Series.dt.is_year_end | 指示日期是否为年的最后一天。 |
Series.dt.is_leap_year | 指示日期是否属于闰年。 |
Series.dt.daysinmonth | 一个月中的天数。 |
Series.dt.days_in_month | 一个月中的天数。 |
Series.dt.tz | 返回时区。 |
Series.dt.freq | 返回此PeriodArray的频率对象。 |
Series.dt.unit | 返回单位。 |
时间增量属性
Series.dt可用于访问系列的值作为时间增量,并返回多个属性。可以像Series.dt.这样访问这些属性。
时间增量属性 | 描述 |
---|---|
Series.dt.qyear | 季度的年份。 |
Series.dt.start_time | 获取周期的开始时间戳。 |
Series.dt.end_time | 获取周期的结束时间戳。 |
时间增量属性
Series.dt可用于访问系列的值作为时间增量,并返回多个属性。可以像Series.dt.这样访问这些属性。
时间增量属性 | 描述 |
---|---|
Series.dt.days | 每个元素的天数。 |
Series.dt.seconds | 每个元素的秒数(>= 0且小于1天)。 |
Series.dt.microseconds | 每个元素的微秒数(>= 0且小于1秒)。 |
Series.dt.nanoseconds | 每个元素的纳秒数(>= 0且小于1微秒)。 |
Series.dt.components | 返回Timedeltas的组件的DataFrame。 |
Series.dt.unit | 单位。 |
字符串处理
Series.str可用于将系列的值作为字符串访问并应用多个方法。可以像Series.str.<function/property>这样访问这些方法。
字符串处理方法 | 描述 |
---|---|
Series.str.capitalize() | 将Series/Index中的字符串转换为首字母大写。 |
Series.str.casefold() | 将Series/Index中的字符串转换为小写形式。 |
Series.str.cat([others, sep, na_rep, join]) | 使用给定的分隔符连接Series/Index中的字符串。 |
Series.str.center(width[, fillchar]) | 在Series/Index中的字符串两侧填充字符。 |
Series.str.contains(pat[, case, flags, na, …]) | 测试每个字符串是否包含模式或正则表达式。 |
Series.str.count(pat[, flags]) | 计算每个字符串中模式出现的次数。 |
Series.str.decode(encoding[, errors]) | 使用指定的编码对Series/Index中的字符字符串进行解码。 |
Series.str.encode(encoding[, errors]) | 使用指定的编码对Series/Index中的字符字符串进行编码。 |
Series.str.endswith(pat[, na]) | 测试每个字符串元素的末尾是否与模式匹配。 |
Series.str.extract(pat[, flags, expand]) | 提取在正则表达式模式中捕获的列作为DataFrame。 |
Series.str.extractall(pat[, flags]) | 将正则表达式模式中捕获的列提取为DataFrame。 |
Series.str.find(sub[, start, end]) | 返回Series/Index中每个字符串的最低索引。 |
Series.str.findall(pat[, flags]) | 在Series/Index中查找模式或正则表达式的所有出现。 |
Series.str.fullmatch(pat[, case, flags, na]) | 确定每个字符串是否完全与正则表达式匹配。 |
Series.str.get(i) | 提取指定位置或键的组件中的元素。 |
Series.str.index(sub[, start, end]) | 返回Series/Index中每个字符串的最低索引。 |
Series.str.join(sep) | 使用传递的分隔符连接Series/Index中的字符串。 |
Series.str.len() | 计算Series/Index中每个元素的长度。 |
Series.str.ljust(width[, fillchar]) | 将Series/Index中的字符串左对齐并填充字符。 |
Series.str.lower() | 将Series/Index中的字符串转换为小写形式。 |
Series.str.lstrip([to_strip]) | 删除Series/Index中字符串的前导字符。 |
Series.str.match(pat[, case, flags, na]) | 确定每个字符串是否以正则表达式匹配。 |
Series.str.normalize(form) | 返回Series/Index中字符串的Unicode规范形式。 |
Series.str.pad(width[, side, fillchar]) | 将Series/Index中的字符串填充到指定宽度。 |
Series.str.partition([sep, expand]) | 将字符串在第一次出现的分隔符处拆分为三个部分。 |
Series.str.removeprefix(prefix) | 从对象系列中删除前缀。 |
Series.str.removesuffix(suffix) | 从对象系列中删除后缀。 |
Series.str.repeat(repeats) | 在Series或Index中重复每个字符串。 |
Series.str.replace(pat, repl[, n, case, …]) | 用给定的值替换Series/Index中的模式/正则表达式的每个出现。 |
Series.str.rfind(sub[, start, end]) | 返回Series/Index中每个字符串的最高索引。 |
Series.str.rindex(sub[, start, end]) | 返回Series/Index中每个字符串的最高索引。 |
Series.str.rjust(width[, fillchar]) | 将Series/Index中的字符串右对齐并填充字符。 |
Series.str.rpartition([sep, expand]) | 将字符串在最后一次出现的分隔符处拆分为三个部分。 |
Series.str.rstrip([to_strip]) | 删除Series/Index中字符串的尾随字符。 |
Series.str.slice([start, stop, step]) | 从Series或Index中的每个元素中切片子字符串。 |
Series.str.slice_replace([start, stop, repl]) | 使用另一个值替换字符串的位置切片。 |
Series.str.split([pat, n, expand, regex]) | 围绕给定的分隔符/定界符拆分字符串。 |
Series.str.rsplit([pat, n, expand]) | 围绕给定的分隔符/定界符拆分字符串。 |
Series.str.startswith(pat[, na]) | 测试每个字符串元素的开头是否与模式匹配。 |
Series.str.strip([to_strip]) | 删除Series/Index中字符串的前导和尾随字符。 |
Series.str.swapcase() | 将Series/Index中的字符串大小写互换。 |
Series.str.title() | 将Series/Index中的字符串转换为标题形式。 |
Series.str.translate(table) | 通过给定的映射表将字符串中的所有字符映射到新的值。 |
Series.str.upper() | 将Series/Index中的字符串转换为大写形式。 |
Series.str.wrap(width, **kwargs) | 将Series/Index中的字符串包装到指定的行宽。 |
Series.str.zfill(width) | 在Series/Index中的字符串左侧填充’0’字符。 |
分类访问器
分类数据类型特定的方法和属性可在Series.cat访问器下使用。
分类访问器 | 描述 |
---|---|
Series.cat.categories | 分类的类别。 |
Series.cat.ordered | 类别是否具有排序关系。 |
Series.cat.codes | 返回代码和索引的Series。 |
稀疏访问器
Sparse访问器提供了针对Sparse-dtype的特定方法和属性。
属性名 | 说明 |
---|---|
Series.sparse.npoints | 非填充值点的数量 |
Series.sparse.density | 非填充值点的百分比(小数形式) |
Series.sparse.fill_value | 数据中的填充值不会被存储 |
Series.sparse.sp_values | 包含非填充值的ndarray |
Series.sparse.from_coo | 从scipy.sparse.coo_matrix创建具有稀疏值的Series |
Series.sparse.to_coo | 从具有MultiIndex的Series创建一个scipy.sparse.coo_matrix |
绘图方法
方法名 | 说明 |
---|---|
Series.plot | 为特定绘图方法的可调用方法和命名空间属性,形式为Series.plot. |
Series.plot.area | 绘制堆叠面积图 |
Series.plot.bar | 绘制垂直条形图 |
Series.plot.barh | 绘制水平条形图 |
Series.plot.box | 绘制DataFrame列的箱线图 |
Series.plot.density | 使用高斯核生成核密度估计图 |
Series.plot.hist | 绘制DataFrame列的直方图 |
Series.plot.kde | 使用高斯核生成核密度估计图 |
Series.plot.line | 将Series或DataFrame绘制为折线图 |
Series.plot.pie | 生成饼图 |
序列化/输入输出/转换方法
方法名 | 说明 |
---|---|
Series.to_pickle | 将对象pickle(序列化)到文件 |
Series.to_csv | 将对象写入逗号分隔值(csv)文件 |
Series.to_dict | 将Series转换为{label -> value}字典或类似字典的对象 |
Series.to_excel | 将对象写入Excel表格 |
Series.to_frame | 将Series转换为DataFrame |
Series.to_xarray | 从pandas对象返回一个xarray对象 |
Series.to_hdf | 使用HDFStore将数据写入HDF5文件 |
Series.to_sql | 将存储在DataFrame中的记录写入SQL数据库 |
Series.to_json | 将对象转换为JSON字符串 |
Series.to_string | 以字符串形式呈现Series |
Series.to_clipboard | 将对象复制到系统剪贴板 |
Series.to_latex | 将对象渲染为LaTeX表格 |
Series.to_markdown | 以适合Markdown的格式打印Series |