./api/polars.exceptions.SchemaError.html)
    * [ polars.exceptions.SchemaFieldNotFoundError ](../../api/polars.exceptions.SchemaFieldNotFoundError.html)
    * [ polars.exceptions.ShapeError ](../../api/polars.exceptions.ShapeError.html)
    * [ polars.exceptions.StructFieldNotFoundError ](../../api/polars.exceptions.StructFieldNotFoundError.html)
    * [ polars.exceptions.TooManyRowsReturnedError ](../../api/polars.exceptions.TooManyRowsReturnedError.html)

  * [ Testing ](../../testing.html) __
    * [ polars.testing.assert_frame_equal ](../../api/polars.testing.assert_frame_equal.html)
    * [ polars.testing.assert_frame_not_equal ](../../api/polars.testing.assert_frame_not_equal.html)
    * [ polars.testing.assert_series_equal ](../../api/polars.testing.assert_series_equal.html)
    * [ polars.testing.assert_series_not_equal ](../../api/polars.testing.assert_series_not_equal.html)
    * [ polars.testing.parametric.dataframes ](../../api/polars.testing.parametric.dataframes.html)
    * [ polars.testing.parametric.series ](../../api/polars.testing.parametric.series.html)
    * [ polars.testing.parametric.column ](../../api/polars.testing.parametric.column.html)
    * [ polars.testing.parametric.columns ](../../api/polars.testing.parametric.columns.html)
    * [ polars.testing.parametric.create_list_strategy ](../../api/polars.testing.parametric.create_list_strategy.html)
    * [ polars.testing.parametric.load_profile ](../../api/polars.testing.parametric.load_profile.html)
    * [ polars.testing.parametric.set_profile ](../../api/polars.testing.parametric.set_profile.html)

  * [ Metadata ](../../metadata.html) __
    * [ polars.build_info ](../../api/polars.build_info.html)
    * [ polars.get_index_type ](../../api/polars.get_index_type.html)
    * [ polars.show_versions ](../../api/polars.show_versions.html)
    * [ polars.thread_pool_size ](../../api/polars.thread_pool_size.html)
    * [ polars.threadpool_size ](../../api/polars.threadpool_size.html)

  * [ __ ](../../../index.html)
  * [ Python API reference ](../../index.html)
  * __
  * [ List ](../list.html)
  * polars.Serie... 

#  polars.Series.list.to_struct  #

Series.list.  to_struct  (

     _ n_field_strategy  :  ToStructStrategy  =  'first_non_null'  _ , 
     _ fields  :  Callable  [  [  [ int  ](https://docs.python.org/3/library/functions.html#int "\(in Python v3.12\)") ]  ,  [ str  ](https://docs.python.org/3/library/stdtypes.html#str "\(in Python v3.12\)") ]  |  Sequence  [  [ str  ](https://docs.python.org/3/library/stdtypes.html#str "\(in Python v3.12\)") ]  |  [ None  ](https://docs.python.org/3/library/constants.html#None "\(in Python v3.12\)") =  None  _ , 
)  →  Series  [ [source]  ](https://github.com/pola-
rs/polars/blob/py-0.20.23/py-polars/polars/series/list.py#L860-L930) #

    

Convert the series of type ` List  ` to a series of type ` Struct  ` .

Parameters  :

    

**n_field_strategy** {‘first_non_null’, ‘max_width’}

    

Strategy to determine the number of fields of the struct.

  * “first_non_null”: set number of fields equal to the length of the first non zero-length sublist. 

  * “max_width”: set number of fields as max length of all sublists. 

**fields**

    

If the name and number of the desired fields is known in advance a list of
field names can be given, which will be assigned by index. Otherwise, to
dynamically assign field names, a custom function can be used; if neither are
set, fields will be ` field_0,  field_1  ..  field_n  ` .

Examples

Convert list to struct with default field name assignment:

    
    
    >>> s1 = pl.Series("n", [[0, 1, 2], [0, 1]])
    >>> s2 = s1.list.to_struct()
    >>> s2
    shape: (2,)
    Series: 'n' [struct[3]]
    [
        {0,1,2}
        {0,1,null}
    ]
    >>> s2.struct.fields
    ['field_0', 'field_1', 'field_2']
    

Convert list to struct with field name assignment by function/index:

    
    
    >>> s3 = s1.list.to_struct(fields=lambda idx: f"n{idx:02}")
    >>> s3.struct.fiel