pandas.DataFrame.dataframe — pandas 3.0.0.dev0+2098.g9c5b9ee823 documentation (original) (raw)
DataFrame.__dataframe__(nan_as_null=False, allow_copy=True)[source]#
Return the dataframe interchange object implementing the interchange protocol.
Note
For new development, we highly recommend using the Arrow C Data Interface alongside the Arrow PyCapsule Interface instead of the interchange protocol
Warning
Due to severe implementation issues, we recommend only considering using the interchange protocol in the following cases:
- converting to pandas: for pandas >= 2.0.3
- converting from pandas: for pandas >= 3.0.0
Parameters:
nan_as_nullbool, default False
nan_as_null is DEPRECATED and has no effect. Please avoid using it; it will be removed in a future release.
allow_copybool, default True
Whether to allow memory copying when exporting. If set to False it would cause non-zero-copy exports to fail.
Returns:
DataFrame interchange object
The object which consuming library can use to ingress the dataframe.
Notes
Details on the interchange protocol:https://data-apis.org/dataframe-protocol/latest/index.html
Examples
df_not_necessarily_pandas = pd.DataFrame({"A": [1, 2], "B": [3, 4]}) interchange_object = df_not_necessarily_pandas.dataframe() interchange_object.column_names() Index(['A', 'B'], dtype='object') df_pandas = pd.api.interchange.from_dataframe( ... interchange_object.select_columns_by_name(["A"]) ... ) df_pandas A 0 1 1 2
These methods (column_names
, select_columns_by_name
) should work for any dataframe library which implements the interchange protocol.