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
# 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
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'>