8. API: DataFrame Objects
Python-oracledb can fetch directly to data frames that expose an Apache Arrow PyCapsule Interface. These can be used by many numerical and data analysis libraries.
See Working with Data Frames for more information, including the type mapping from Oracle Database types to Arrow data types.
8.1. DataFrame Class
- class oracledb.DataFrame
A DataFrame object is returned by the methods
Connection.fetch_df_all(),Connection.fetch_df_batches(),AsyncConnection.fetch_df_all(), orAsyncConnection.fetch_df_batches().Each column in a DataFrame exposes an Apache Arrow PyCapsule interface, giving access to the underlying Apache Arrow array.
This object is an extension to the DB API definition.Changed in version 3.3.0: Removed the prefix “Oracle” from the class name.
Added in version 3.0.0.
8.1.1. DataFrame Methods
- DataFrame.column_arrays() list[ArrowArray]
Returns a list of ArrowArray objects, each containing a select list column.
- DataFrame.column_names() list[str]
Returns a list of the column names in the data frame.
- DataFrame.get_column(i: int) ArrowArray
Returns an ArrowArray object for the column at the given index
i. If the index is out of range, an IndexError exception is raised.
- DataFrame.get_column_by_name(name: str) ArrowArray
Returns an ArrowArray object for the column with the given name
name. If the column name is not found, a KeyError exception is raised.
- DataFrame.num_columns() int
Returns the number of columns in the data frame.
- DataFrame.num_rows() int
Returns the number of rows in the data frame.
8.2. ArrowArray Objects
- class oracledb.ArrowArray
ArrowArray objects are returned by
DataFrame.column_arrays().These are used for conversion to PyArrow Tables, see Working with Data Frames.
Changed in version 3.3.0: Removed the prefix “Oracle” from the class name.
Added in version 3.0.0.