class_docstr: Namespace for string related expressions.
class_docstr_tok: ["Namespace","for","string","related","expressions","."]
docstr: Split the string by a substring, restricted to returning at most `n` items.
  
  If the number of possible splits is less than `n-1`, the remaining field
  elements will be null. If the number of possible splits is `n-1` or greater,
  the last (nth) substring will contain the remainder of the string.
  
  Parameters
  ----------
  by
      Substring to split by.
  n
      Max number of items to return.
  
  Returns
  -------
  Expr
      Expression of data type :class:`Struct` with fields of data type
      :class:`String`.
  
  Examples
  --------
  >>> df = pl.DataFrame({"s": ["foo bar", None, "foo-bar", "foo bar baz"]})
  >>> df.with_columns(pl.col("s").str.splitn(" ", 2).alias("fields"))
  shape: (4, 2)
  ┌─────────────┬───────────────────┐
  │ s           ┆ fields            │
  │ ---         ┆ ---               │
  │ str         ┆ struct[2]         │
  ╞═════════════╪═══════════════════╡
  │ foo bar     ┆ {"foo","bar"}     │
  │ null        ┆ {null,null}       │
  │ foo-bar     ┆ {"foo-bar",null}  │
  │ foo bar baz ┆ {"foo","bar baz"} │
  └─────────────┴───────────────────┘
  
  Split string values in column s in exactly 2 parts and assign
  each part to a new column.
  
  >>> df.with_columns(
  ...     [
  ...         pl.col("s")
  ...         .str.splitn(" ", 2)
  ...         .struct.rename_fields(["first_part", "second_part"])
  ...         .alias("fields"),
  ...     ]
  ... ).unnest("fields")
  shape: (4, 3)
  ┌─────────────┬────────────┬─────────────┐
  │ s           ┆ first_part ┆ second_part │
  │ ---         ┆ ---        ┆ ---         │
  │ str         ┆ str        ┆ str         │
  ╞═════════════╪════════════╪═════════════╡
  │ foo bar     ┆ foo        ┆ bar         │
  │ null        ┆ null       ┆ null        │
  │ foo-bar     ┆ foo-bar    ┆ null        │
  │ foo bar baz ┆ foo        ┆ bar baz     │
  └─────────────┴────────────┴─────────────┘
docstr_tok: ["Split","the","string","by","a","substring",",","restricted","to","returning","at","most","`","n","`","items",".","If","the","number","of","possible","splits","is","less","than","`","n-1","`",",","the","remaining","field","elements","will","be","null",".","If","the","number","of","possible","splits","is","`","n-1","`","or","greater",",","the","last","(","nth",")","substring","will","contain","the","remainder","of","the","string",".","Parameters","--","--","--","--","--","by","Substring","to","split","by",".","n","Max","number","of","items","to","return",".","Returns","--","--","--","-","Expr","Expression","of","data","type",":","class",":","`","Struct","`","with","fields","of","data","type",":","class",":","`","String","`",".","Examples","--","--","--","--",">",">",">","df","=","pl.DataFrame","(","{","``","s","''",":","[","``","foo","bar","''",",","None",",","``","foo-bar","''",",","``","foo","bar","baz","''","]","}",")",">",">",">","df.with_columns","(","pl.col","(","``","s","''",")",".str.splitn","(","``","``",",","2",")",".alias","(","``","fields","''",")",")","shape",":","(","4",",","2",")","\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510","\u2502","s","\u2506","fields","\u2502","\u2502","--","-","\u2506","--","-","\u2502","\u2502","str","\u2506","struct","[","2","]","\u2502","\u255e\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2561","\u2502","foo","bar","\u2506","{","``","foo","''",",","''","bar","''","}","\u2502","\u2502","null","\u2506","{","null",",","null","}","\u2502","\u2502","foo-bar","\u2506","{","``","foo-bar","''",",","null","}","\u2502","\u2502","foo","bar","baz","\u2506","{","``","foo","''",",","''","bar","baz","''","}","\u2502","\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518","Split","string","values","in","column","s","in","exactly","2","parts","and","assign","each","part","to","a","new","column",".",">",">",">","df.with_columns","(","...","[","...","pl.col","(","``","s","''",")","...",".str.splitn","(","``","``",",","2",")","...",".struct.rename_fields","(","[","``","first_part","''",",","``","second_part","''","]",")","...",".alias","(","``","fields","''",")",",","...","]","...",")",".unnest","(","``","fields","''",")","shape",":","(","4",",","3",")","\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510","\u2502","s","\u2506","first_part","\u2506","second_part","\u2502","\u2502","--","-","\u2506","--","-","\u2506","--","-","\u2502","\u2502","str","\u2506","str","\u2506","str","\u2502","\u255e\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2561","\u2502","foo","bar","\u2506","foo","\u2506","bar","\u2502","\u2502","null","\u2506","null","\u2506","null","\u2502","\u2502","foo-bar","\u2506","foo-bar","\u2506","null","\u2502","\u2502","foo","bar","baz","\u2506","foo","\u2506","bar","baz","\u2502","\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"]
code: def splitn(self, by: IntoExpr, n: int) -> Expr:
      """
      Split the string by a substring, restricted to returning at most `n` items.
  
      If the number of possible splits is less than `n-1`, the remaining field
      elements will be null. If the number of possible splits is `n-1` or greater,
      the last (nth) substring will contain the remainder of the string.
  
      Parameters
      ----------
      by
          Substring to split by.
      n
          Max number of items to return.
  
      Returns
      -------
      Expr
          Expression of data type :class:`Struct` with fields of data type
          :class:`String`.
  
      Examples
      --------
      >>> df = pl.DataFrame({"s": ["foo bar", None, "foo-bar", "foo bar baz"]})
      >>> df.with_columns(pl.col("s").str.splitn(" ", 2).alias("fields"))
      shape: (4, 2)
      ┌─────────────┬───────────────────┐
      │ s           ┆ fields            │
      │ ---         ┆ ---               │
      │ str         ┆ struct[2]         │
      ╞═════════════╪═══════════════════╡
      │ foo bar     ┆ {"foo","bar"}     │
      │ null        ┆ {null,null}       │
      │ foo-bar     ┆ {"foo-bar",null}  │
      │ foo bar baz ┆ {"foo","bar baz"} │
      └─────────────┴───────────────────┘
  
      Split string values in column s in exactly 2 parts and assign
      each part to a new column.
  
      >>> df.with_columns(
      ...     [
      ...         pl.col("s")
      ...         .str.splitn(" ", 2)
      ...         .struct.rename_fields(["first_part", "second_part"])
      ...         .alias("fields"),
      ...     ]
      ... ).unnest("fields")
      shape: (4, 3)
      ┌─────────────┬────────────┬─────────────┐
      │ s           ┆ first_part ┆ second_part │
      │ ---         ┆ ---        ┆ ---         │
      │ str         ┆ str        ┆ str         │
      ╞═════════════╪════════════╪═════════════╡
      │ foo bar     ┆ foo        ┆ bar         │
      │ null        ┆ null       ┆ null        │
      │ foo-bar     ┆ foo-bar    ┆ null        │
      │ foo bar baz ┆ foo        ┆ bar baz     │
      └─────────────┴────────────┴─────────────┘
  
      """
      by = parse_as_expression(by, str_as_lit=True)
      return wrap_expr(self._pyexpr.str_splitn(by, n))
  
imports: from __future__ import annotations
  import warnings
  from typing import TYPE_CHECKING
  import polars._reexport
  from polars import functions
  from polars.datatypes import Date, Datetime, Int32, Time, py_type_to_dtype
  from polars.exceptions import ChronoFormatWarning
  from polars.utils._parse_expr_input import parse_as_expression
  from polars.utils._wrap import wrap_expr
  from polars.utils.deprecation import deprecate_renamed_function, deprecate_renamed_parameter, rename_use_earliest_to_ambiguous
  from polars.utils.various import find_stacklevel
label_desc: Use image node_id 34 for calling the ExprStringNameSpace obj's underlying member method code with example usage: obj.splitn(by, n) and returns: wrap_expr