pandas.Series.struct.field#
- Series.struct.field(name_or_index)[source]#
Extract a child field of a struct as a Series.
- Parameters:
- name_or_indexstr | int
Name or index of the child field to extract.
- Returns:
- pandas.Series
The data corresponding to the selected child field.
See also
Series.struct.explode
Return all child fields as a DataFrame.
Examples
>>> import pyarrow as pa >>> s = pd.Series( ... [ ... {"version": 1, "project": "pandas"}, ... {"version": 2, "project": "pandas"}, ... {"version": 1, "project": "numpy"}, ... ], ... dtype=pd.ArrowDtype(pa.struct( ... [("version", pa.int64()), ("project", pa.string())] ... )) ... )
Extract by field name.
>>> s.struct.field("project") 0 pandas 1 pandas 2 numpy Name: project, dtype: string[pyarrow]
Extract by field index.
>>> s.struct.field(0) 0 1 1 2 2 1 Name: version, dtype: int64[pyarrow]