Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.__array__#

Series.__array__(dtype=None,copy=None)[source]#

Return the values as a NumPy array.

Users should not call this directly. Rather, it is invoked bynumpy.array() andnumpy.asarray().

Parameters:
dtypestr or numpy.dtype, optional

The dtype to use for the resulting NumPy array. By default,the dtype is inferred from the data.

copybool or None, optional

Seenumpy.asarray().

Returns:
numpy.ndarray

The values in the series converted to anumpy.ndarraywith the specifieddtype.

See also

array

Create a new array from data.

Series.array

Zero-copy view to the array backing the Series.

Series.to_numpy

Series method for similar behavior.

Examples

>>>ser=pd.Series([1,2,3])>>>np.asarray(ser)array([1, 2, 3])

For timezone-aware data, the timezones may be retained withdtype='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)

Or the values may be localized to UTC and the tzinfo discarded withdtype='datetime64[ns]'

>>>np.asarray(tzser,dtype="datetime64[ns]")array(['1999-12-31T23:00:00.000000000', ...],      dtype='datetime64[ns]')

[8]ページ先頭

©2009-2025 Movatter.jp