Retrieve the flattened underlying data of a Series

The ravel() method of pandas Series class returns the underlying data which is an ndarray. The Python example prints the input Series and the output ndarray.

Series Manipulations Updated 2 Nov 2019 1 min read

Overview

  • The underlying data storage in the pandas classes, Series and DataFrame is the type numpy.ndarray.
  • The instance method ravel() returns the flattened underlying data for a panads Series object.
  • This method is often useful when sending data to interfaces where a pandas Series is not accepted, but a numpy ndarray is accepted.

Example

python
# Example Python program that retrieves the underlying ndarray

import pandas as pds

numberList      = [50, 60, 70, 80, 90];

numberSeries    = pds.Series(numberList);

underlying      = numberSeries.ravel();

print("Data present in the pandas Series:");

print(numberSeries);

print("Data as the ndarray:");

print(underlying);

print(type(underlying));

Output

Output
Data present in the pandas Series:

0    50

1    60

2    70

3    80

4    90

dtype: int64

Data as the ndarray:

[50 60 70 80 90]

<class 'numpy.ndarray'>