[yt-svn] commit/yt: jzuhone: Merged in MatthewTurk/yt (pull request #1659)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Jul 29 07:24:15 PDT 2015
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/6c6b39d2fe53/
Changeset: 6c6b39d2fe53
Branch: yt
User: jzuhone
Date: 2015-07-29 14:24:03+00:00
Summary: Merged in MatthewTurk/yt (pull request #1659)
Add to_dataframe
Affected #: 1 file
diff -r 6faa62d05f5e8a6011455b345be4b49aa0a08675 -r 6c6b39d2fe53a28aa99acb516ca28f51cdf77e3f yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -426,6 +426,43 @@
else:
self.index.save_object(self, name)
+ def to_dataframe(self, fields = None):
+ r"""Export a data object to a pandas DataFrame.
+
+ This function will take a data object and construct from it and
+ optionally a list of fields a pandas DataFrame object. If pandas is
+ not importable, this will raise ImportError.
+
+ Parameters
+ ----------
+ fields : list of strings or tuples, default None
+ If this is supplied, it is the list of fields to be exported into
+ the data frame. If not supplied, whatever fields presently exist
+ will be used.
+
+ Returns
+ -------
+ df : DataFrame
+ The data contained in the object.
+
+ Examples
+ --------
+
+ >>> dd = ds.all_data()
+ >>> df1 = dd.to_dataframe(["density", "temperature"])
+ >>> dd["velocity_magnitude"]
+ >>> df2 = dd.to_dataframe()
+ """
+ import pandas as pd
+ data = {}
+ if fields is not None:
+ for f in fields:
+ data[f] = self[f]
+ else:
+ data.update(self.field_data)
+ df = pd.DataFrame(data)
+ return df
+
def to_glue(self, fields, label="yt", data_collection=None):
"""
Takes specific *fields* in the container and exports them to
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list