cudf.DataFrame.to_pandas#

DataFrame.to_pandas(*, nullable: bool = False, arrow_type: bool = False) DataFrame#

Convert to a Pandas DataFrame.

Parameters:
nullableBoolean, Default False

If nullable is True, the resulting columns in the dataframe will be having a corresponding nullable Pandas dtype. If there is no corresponding nullable Pandas dtype present, the resulting dtype will be a regular pandas dtype. If nullable is False, the resulting columns will either convert null values to np.nan or None depending on the dtype.

arrow_typebool, Default False

Return the columns with a pandas.ArrowDtype

Returns:
outPandas DataFrame

Notes

nullable and arrow_type cannot both be set to True

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [0, 1, 2], 'b': [-3, 2, 0]})
>>> pdf = df.to_pandas()
>>> pdf
   a  b
0  0 -3
1  1  2
2  2  0
>>> type(pdf)
<class 'pandas.core.frame.DataFrame'>

nullable=True converts the result to pandas nullable types:

>>> df = cudf.DataFrame({'a': [0, None, 2], 'b': [True, False, None]})
>>> df
      a      b
0     0   True
1  <NA>  False
2     2   <NA>
>>> pdf = df.to_pandas(nullable=True)
>>> pdf
      a      b
0     0   True
1  <NA>  False
2     2   <NA>
>>> pdf.dtypes
a      Int64
b    boolean
dtype: object
>>> pdf = df.to_pandas(nullable=False)
>>> pdf
     a      b
0  0.0   True
1  NaN  False
2  2.0   None
>>> pdf.dtypes
a    float64
b     object
dtype: object

arrow_type=True converts the result to pandas.ArrowDtype:

>>> df.to_pandas(arrow_type=True).dtypes
a    int64[pyarrow]
b     bool[pyarrow]
dtype: object