用法:
Series.__array__(dtype=None)
將值作為 NumPy 數組返回。
用戶不應直接調用它。相反,它由
numpy.array()
和numpy.asarray()
調用。- dtype:str 或 numpy.dtype,可選
用於生成的 NumPy 數組的 dtype。默認情況下,dtype 是從數據中推斷出來的。
- numpy.ndarray
係列中的值轉換為具有指定
dtype
的numpy.ndarray
。
參數:
返回:
例子:
>>> ser = pd.Series([1, 2, 3]) >>> np.asarray(ser) array([1, 2, 3])
對於timezone-aware 數據,時區可以保留為
dtype='object'
>>> tzser = pd.Series(pd.date_range('2000', periods=2, tz="CET")) >>> np.asarray(tzser, dtype="object") array([Timestamp('2000-01-01 00:00:00+0100', tz='CET'), Timestamp('2000-01-02 00:00:00+0100', tz='CET')], dtype=object)
或者這些值可能被本地化為 UTC,並且 tzinfo 被
dtype='datetime64[ns]'
丟棄>>> np.asarray(tzser, dtype="datetime64[ns]") array(['1999-12-31T23:00:00.000000000', ...], dtype='datetime64[ns]')
相關用法
- Python pandas.Series.add_prefix用法及代碼示例
- Python pandas.Series.map用法及代碼示例
- Python pandas.Series.max用法及代碼示例
- Python pandas.Series.str.isdecimal用法及代碼示例
- Python pandas.Series.str.get用法及代碼示例
- Python pandas.Series.to_csv用法及代碼示例
- Python pandas.Series.dt.day_name用法及代碼示例
- Python pandas.Series.sample用法及代碼示例
- Python pandas.Series.head用法及代碼示例
- Python pandas.Series.eq用法及代碼示例
- Python pandas.Series.plot.line用法及代碼示例
- Python pandas.Series.to_pickle用法及代碼示例
- Python pandas.Series.between_time用法及代碼示例
- Python pandas.Series.reindex_like用法及代碼示例
- Python pandas.Series.dt.is_year_end用法及代碼示例
- Python pandas.Series.repeat用法及代碼示例
- Python pandas.Series.str.replace用法及代碼示例
- Python pandas.Series.update用法及代碼示例
- Python pandas.Series.iat用法及代碼示例
- Python pandas.Series.divide用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Series.__array__。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。