pandas_paddles.paddles.str_join#
- pandas_paddles.paddles.str_join(sep, col1, *cols)[source]#
Create expression to join multiple columns in a string.
This is similar to
str.join- Parameters
sep (str) – The separator
col1 (Union[str, pandas_paddles.contexts.DataframeContext]) –
The columns to be joined. These can be either
strorDF-expressions. If astris passed, it’s taken as column name and the respectiveDF-expression is created.In both cases the expression is first casted to
strusingpandas.Series.astype().cols (Union[str, pandas_paddles.contexts.DataframeContext]) –
The columns to be joined. These can be either
strorDF-expressions. If astris passed, it’s taken as column name and the respectiveDF-expression is created.In both cases the expression is first casted to
strusingpandas.Series.astype().
- Returns
The
DF-expression, a callable taking aDataFrameas argument.- Return type
Examples
Reference columns with their names:
>>> df = pd.DataFrame({"a": list("abc"), "b": list("XYZ"), "c": range(3)}) >>> df.assign(a_plus_b=str_join("+", "a", "b")) a b c a_plus_b 0 a X 0 a+X 1 b Y 1 b+Y 2 c Z 2 c+Z
Reference columns with
DF-expressions:>>> df.assign(a_plus_b=str_join("+", "a", DF["b"].str.lower())) a b c a_plus_b 0 a X 0 a+x 1 b Y 1 b+y 2 c Z 2 c+z
Non-string columns are converted:
>>> df.assign(a_plus_c=str_join("+", "a", "c")) a b c a_plus_b 0 a X 0 a+0 1 b Y 1 b+1 2 c Z 2 c+2