本文簡要介紹
pyspark.pandas.Series.values
的用法。用法:
property Series.values
返回 DataFrame 或係列的 Numpy 表示形式。
警告
我們建議改用
DataFrame.to_numpy()
或Series.to_numpy()
。注意
僅當生成的 NumPy ndarray 預計很小時才應使用此方法,因為所有數據都加載到驅動程序的內存中。
- numpy.ndarray
返回:
例子:
所有列都具有相同類型(例如 int64)的 DataFrame 會生成相同類型的數組。
>>> df = ps.DataFrame({'age': [ 3, 29], ... 'height': [94, 170], ... 'weight': [31, 115]}) >>> df age height weight 0 3 94 31 1 29 170 115 >>> df.dtypes age int64 height int64 weight int64 dtype: object >>> df.values array([[ 3, 94, 31], [ 29, 170, 115]])
具有混合類型列(例如 str/object、int64、float32)的 DataFrame 會生成容納這些混合類型(例如 object)的最廣泛類型的 ndarray。
>>> df2 = ps.DataFrame([('parrot', 24.0, 'second'), ... ('lion', 80.5, 'first'), ... ('monkey', np.nan, None)], ... columns=('name', 'max_speed', 'rank')) >>> df2.dtypes name object max_speed float64 rank object dtype: object >>> df2.values array([['parrot', 24.0, 'second'], ['lion', 80.5, 'first'], ['monkey', nan, None]], dtype=object)
對於係列,
>>> ps.Series([1, 2, 3]).values array([1, 2, 3])
>>> ps.Series(list('aabc')).values array(['a', 'a', 'b', 'c'], dtype=object)
相關用法
- Python pyspark Series.value_counts用法及代碼示例
- 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用法及代碼示例
注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.pandas.Series.values。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。