本文簡要介紹
pyspark.pandas.Series.xs
的用法。用法:
Series.xs(key: Union[Any, Tuple[Any, …]], level: Optional[int] = None) → pyspark.pandas.series.Series
從係列返回橫截麵。
此方法采用
key
參數來選擇 MultiIndex 特定級別的數據。- key:標簽或標簽元組
標簽包含在索引中,或部分包含在 MultiIndex 中。
- level:對象,默認為前 n 級(n=1 或 len(key))
如果鍵部分包含在 MultiIndex 中,請指明使用了哪些級別。級別可以通過標簽或位置來引用。
- Series
與所選索引級別對應的原始係列的橫截麵。
參數:
返回:
例子:
>>> midx = pd.MultiIndex([['a', 'b', 'c'], ... ['lama', 'cow', 'falcon'], ... ['speed', 'weight', 'length']], ... [[0, 0, 0, 1, 1, 1, 2, 2, 2], ... [0, 0, 0, 1, 1, 1, 2, 2, 2], ... [0, 1, 2, 0, 1, 2, 0, 1, 2]]) >>> s = ps.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3], ... index=midx) >>> s a lama speed 45.0 weight 200.0 length 1.2 b cow speed 30.0 weight 250.0 length 1.5 c falcon speed 320.0 weight 1.0 length 0.3 dtype: float64
獲取指定索引處的值
>>> s.xs('a') lama speed 45.0 weight 200.0 length 1.2 dtype: float64
獲取多個索引處的值
>>> s.xs(('a', 'lama')) speed 45.0 weight 200.0 length 1.2 dtype: float64
獲取指定索引和級別的值
>>> s.xs('lama', level=1) a speed 45.0 weight 200.0 length 1.2 dtype: float64
相關用法
- Python pyspark Series.asof用法及代碼示例
- Python pyspark Series.to_frame用法及代碼示例
- Python pyspark Series.rsub用法及代碼示例
- Python pyspark Series.mod用法及代碼示例
- Python pyspark Series.str.join用法及代碼示例
- Python pyspark Series.str.startswith用法及代碼示例
- Python pyspark Series.dt.is_quarter_end用法及代碼示例
- Python pyspark Series.dropna用法及代碼示例
- Python pyspark Series.sub用法及代碼示例
- Python pyspark Series.sum用法及代碼示例
- Python pyspark Series.gt用法及代碼示例
- Python pyspark Series.iloc用法及代碼示例
- Python pyspark Series.explode用法及代碼示例
- Python pyspark Series.str.slice_replace用法及代碼示例
- Python pyspark Series.dt.is_month_end用法及代碼示例
- Python pyspark Series.plot.barh用法及代碼示例
- Python pyspark Series.between用法及代碼示例
- Python pyspark Series.floordiv用法及代碼示例
- Python pyspark Series.describe用法及代碼示例
- Python pyspark Series.ndim用法及代碼示例
- Python pyspark Series.str.rjust用法及代碼示例
- Python pyspark Series.loc用法及代碼示例
- Python pyspark Series.add_prefix用法及代碼示例
- Python pyspark Series.truediv用法及代碼示例
- Python pyspark Series.sem用法及代碼示例
注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.pandas.Series.xs。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。