DataSetAttributes.to_pandas

Contents

DataSetAttributes.to_pandas#

DataSetAttributes.to_pandas() pandas.DataFrame[source]#

Return this attribute set as a pandas.DataFrame.

Each array becomes a column. Multi-component arrays are expanded to one column per component, named {array_name}_{i}. Only point_data and cell_data can be converted. field_data raises ValueError.

Requires pandas.

Returns:
pandas.DataFrame

DataFrame with one column per (expanded) array and valid_array_len rows.

Notes

Pandas consolidates the dict of columns into internal blocks during construction, which copies the data. The returned DataFrame is effectively a snapshot and does not share memory with VTK. Callers that need zero-copy access should use to_arrow() instead.

Examples

>>> import pyvista as pv
>>> mesh = pv.Cube()
>>> mesh.clear_data()
>>> mesh.point_data['scalars'] = range(mesh.n_points)
>>> df = mesh.point_data.to_pandas()
>>> list(df.columns)
['scalars']