Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Added awkward.frompandas() for intuitive DataFrame -> Tables conversion #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions awkward/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def concatenate(arrays, axis=0):
from awkward.persist import serialize, deserialize, save, load, hdf5

from awkward.arrow import toarrow, fromarrow, toparquet, fromparquet
from awkward.util import topandas
from awkward.util import frompandas, topandas

# convenient access to the version number
from awkward.version import __version__

__all__ = ["numpy", "AwkwardArray", "ChunkedArray", "AppendableArray", "IndexedArray", "SparseArray", "JaggedArray", "MaskedArray", "BitMaskedArray", "IndexedMaskedArray", "Methods", "ObjectArray", "Table", "UnionArray", "VirtualArray", "StringArray", "fromiter", "serialize", "deserialize", "save", "load", "hdf5", "toarrow", "fromarrow", "toparquet", "fromparquet", "topandas", "__version__"]
__all__ = ["numpy", "AwkwardArray", "ChunkedArray", "AppendableArray", "IndexedArray", "SparseArray", "JaggedArray", "MaskedArray", "BitMaskedArray", "IndexedMaskedArray", "Methods", "ObjectArray", "Table", "UnionArray", "VirtualArray", "StringArray", "fromiter", "serialize", "deserialize", "save", "load", "hdf5", "toarrow", "fromarrow", "toparquet", "fromparquet", "frompandas", "topandas", "__version__"]

__path__ = __import__("pkgutil").extend_path(__path__, __name__)
15 changes: 14 additions & 1 deletion awkward/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,20 @@ class NDArrayOperatorsMixin(object):
__abs__ = _unary_method(um.absolute, 'abs')
__invert__ = _unary_method(um.invert, 'invert')

################################################################ conversion of arrays to Pandas
################################################################ conversion of arrays from/to Pandas


def frompandas(dataframe):
"""Converts a Pandas DataFrame to an Awkward Table

:param dataframe: Pandas DataFrame
:return: awkward.Table
"""

import awkward.array.table

return awkward.Table({name: dataframe[name].values for name in dataframe.columns})


def topandas(array, flatten=False):
import pandas
Expand Down