Document Pandas<->Arrow conversion

Change-Id: Icd19435eb0202a972817adfd880983b1c937bef1
This commit is contained in:
Uwe L. Korn committed 2016-11-04 09:54:19 +01:00
1 parent b5b4df525e
commit 744202a61d
3 files changed
+78

No files matched your search

+2
View File
@@ -34,6 +34,8 @@ structures.
:maxdepth: 2
:caption: Getting Started
Installing pyarrow <install.rst>
Pandas <pandas.rst>
Module Reference <modules.rst>
.. toctree::
+61
View File
@@ -0,0 +1,61 @@
.. Licensed to the Apache Software Foundation (ASF) under one
.. or more contributor license agreements. See the NOTICE file
.. distributed with this work for additional information
.. regarding copyright ownership. The ASF licenses this file
.. to you under the Apache License, Version 2.0 (the
.. "License"); you may not use this file except in compliance
.. with the License. You may obtain a copy of the License at
.. http://www.apache.org/licenses/LICENSE-2.0
.. Unless required by applicable law or agreed to in writing,
.. software distributed under the License is distributed on an
.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
.. KIND, either express or implied. See the License for the
.. specific language governing permissions and limitations
.. under the License.
Pandas Interface
================
To interface with Pandas, PyArrow provides various conversion routines to
consume Pandas structures and convert back to them.
DataFrames
----------
The equivalent to a Pandas DataFrame in Arrow is a :class:`pyarrow.table.Table`.
Both consist of a set of named columns of equal length. While Pandas only
supports flat columnas, the Table also provides nested columns, thus it can
represent more data than a DataFrame, so a full conversion is not always possible.
Conversion from a Table to a DataFrame is done by calling
:meth:`pyarrow.table.Table.to_pandas`. The inverse is then achieved by using
:meth:`pyarrow.from_pandas_dataframe`. This conversion routine provides the
convience parameter ``timestamps_to_ms``. Although Arrow supports timestamps of
different resolutions, Pandas only supports nanosecond timestamps and most
other systems (e.g. Parquet) only work on millisecond timestamps. This parameter
can be used to already do the time conversion during the Pandas to Arrow
conversion.
.. code-block:: python
import pyarrow as pa
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3]})
# Convert from Pandas to Arrow
table = pa.from_pandas_dataframe(df)
# Convert back to Pandas
df_new = table.to_pandas()
Series
------
In Arrow, the most similar structure to a Pandas Series is an Array.
It is a vector that contains data of the same type as linear memory. You can
convert a Pandas Series to an Arrow Array using :meth:`pyarrow.array.from_pandas_series`.
As Arrow Arrays are always nullable, you can supply an optional mask using
the ``mask`` parameter to mark all null-entries.
+15
View File
@@ -293,6 +293,8 @@ cdef class RecordBatch:
cdef class Table:
'''
A collection of top-level named, equal length Arrow arrays.
Do not call this class's constructor directly.
'''
@@ -330,6 +332,19 @@ cdef class Table:
@staticmethod
def from_arrays(names, arrays, name=None):
"""
Construct a Table from Arrow Arrays
Parameters
----------
names: list of str
Names for the table columns
arrays: list of pyarrow.array.Array
Equal-length arrays that should form the table.
name: str
(optional) name for the Table
"""
cdef:
Array arr
c_string c_name