- API reference
- Series
- pandas.Serie...
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 | bytes | int | expression | list
Name or index of the child field to extract.
For list-like inputs, this will index into a nestedstruct.
- Returns:
- pandas.Series
The data corresponding to the selected child field.
See also
Series.struct.explodeReturn all child fields as a DataFrame.
Notes
The name of the resulting Series will be set using the followingrules:
For string, bytes, or integername_or_index (or a list of these, fora nested selection), the Series name is set to the selectedfield’s name.
For a
pyarrow.compute.Expression, this is set tothe string form of the expression.For list-likename_or_index, the name will be set to thename of the final field selected.
Examples
>>>importpyarrowaspa>>>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 pandas1 pandas2 numpyName: project, dtype: string[pyarrow]
Extract by field index.
>>>s.struct.field(0)0 11 22 1Name: version, dtype: int64[pyarrow]
Or an expression
>>>importpyarrow.computeaspc>>>s.struct.field(pc.field("project"))0 pandas1 pandas2 numpyName: project, dtype: string[pyarrow]
For nested struct types, you can pass a list of values to indexmultiple levels:
>>>version_type=pa.struct([...("major",pa.int64()),...("minor",pa.int64()),...])>>>s=pd.Series(...[...{"version":{"major":1,"minor":5},"project":"pandas"},...{"version":{"major":2,"minor":1},"project":"pandas"},...{"version":{"major":1,"minor":26},"project":"numpy"},...],...dtype=pd.ArrowDtype(pa.struct(...[("version",version_type),("project",pa.string())]...))...)>>>s.struct.field(["version","minor"])0 51 12 26Name: minor, dtype: int64[pyarrow]>>>s.struct.field([0,0])0 11 22 1Name: major, dtype: int64[pyarrow]