pandas.DataFrame.values¶
Return a Numpy representation of the DataFrame.
Warning
We recommend using DataFrame.to_numpy()
instead.
Only the values in the DataFrame will be returned, the axes labels will be removed.
- return
numpy.ndarray The values of the DataFrame.
Limitations¶
Only numeric values supported as an output
- The dtype will be a lower-common-denominator dtype (implicit upcasting);
that is to say if the dtypes (even of numeric types) are mixed, the one that accommodates all will be chosen. Use this with care if you are not dealing with the blocks. e.g. If the dtypes are float16 and float32, dtype will be upcast to float32. If dtypes are int32 and uint8, dtype will be upcast to int32. By numpy.find_common_type() convention, mixing int64 and uint64 will result in a float64 dtype.
Examples¶
import pandas as pd
from numba import njit
@njit
def dataframe_values():
df = pd.DataFrame({'age': [3, 29], 'height': [94, 170], 'weight': [31, 115]})
result = df.values
return result # Numpy array of dataframe values: array([[3, 94, 31], [29, 170, 115]], dtype=int64)
print(dataframe_values())
$ python ./dataframe/dataframe_values.py
[[ 3 94 31]
[ 29 170 115]]
See also
- DataFrame.to_numpy
Recommended alternative to this method.
- DataFrame.index
Retrieve the index labels.
- DataFrame.columns
Retrieving the column names.