Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.values#

propertyDataFrame.values[source]#

Return a Numpy representation of the DataFrame.

Warning

We recommend usingDataFrame.to_numpy() instead.

Only the values in the DataFrame will be returned, the axes labelswill be removed.

Returns:
numpy.ndarray

The values of the DataFrame.

See also

DataFrame.to_numpy

Recommended alternative to this method.

DataFrame.index

Retrieve the index labels.

DataFrame.columns

Retrieving the column names.

Notes

The dtype will be a lower-common-denominator dtype (implicitupcasting); that is to say if the dtypes (even of numeric types)are mixed, the one that accommodates all will be chosen. Use thiswith care if you are not dealing with the blocks.

e.g. If the dtypes are float16 and float32, dtype will be upcast tofloat32. If dtypes are int32 and uint8, dtype will be upcast toint32. Bynumpy.find_common_type() convention, mixing int64and uint64 will result in a float64 dtype.

Examples

A DataFrame where all columns are the same type (e.g., int64) resultsin an array of the same type.

>>>df=pd.DataFrame({'age':[3,29],...'height':[94,170],...'weight':[31,115]})>>>df   age  height  weight0    3      94      311   29     170     115>>>df.dtypesage       int64height    int64weight    int64dtype: object>>>df.valuesarray([[  3,  94,  31],       [ 29, 170, 115]])

A DataFrame with mixed type columns(e.g., str/object, int64, float32)results in an ndarray of the broadest type that accommodates thesemixed types (e.g., object).

>>>df2=pd.DataFrame([('parrot',24.0,'second'),...('lion',80.5,1),...('monkey',np.nan,None)],...columns=('name','max_speed','rank'))>>>df2.dtypesname          objectmax_speed    float64rank          objectdtype: object>>>df2.valuesarray([['parrot', 24.0, 'second'],       ['lion', 80.5, 1],       ['monkey', nan, None]], dtype=object)

[8]ページ先頭

©2009-2025 Movatter.jp