modin.pandas.melt

modin.pandas.melt(frame, id_vars=None, value_vars=None, var_name=None, value_name='value', col_level=None, ignore_index: bool = True)[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.26.0/snowpark-python/src/snowflake/snowpark/modin/plugin/extensions/general_overrides.py#L104-L123)

Unpivot a DataFrame from wide to long format, optionally leaving identifiers set.

Parameters:
  • id_vars (list of identifiers to retain in the result) –

  • value_vars (list of columns to unpivot on) – defaults to all columns, excluding the id_vars columns

  • var_name (variable name, defaults to "variable") –

  • value_name (value name, defaults to "value") –

  • col_level (int, not implemented) –

  • ignore_index (bool, not implemented) –

Returns:

unpivoted on the value columns

Return type:

DataFrame

Examples

>>> df = pd.DataFrame({'A': {0: 'a', 1: 'b', 2: 'c'},
...           'B': {0: 1, 1: 3, 2: 5},
...           'C': {0: 2, 1: 4, 2: 6}})
Copy
>>> pd.melt(df)
  variable value
0        A     a
1        A     b
2        A     c
3        B     1
4        B     3
5        B     5
6        C     2
7        C     4
8        C     6
Copy
>>> df = pd.DataFrame({'A': {0: 'a', 1: 'b', 2: 'c'},
...           'B': {0: 1, 1: 3, 2: 5},
...           'C': {0: 2, 1: 4, 2: 6}})
>>> pd.melt(df, id_vars=['A'], value_vars=['B'], var_name='myVarname', value_name='myValname')
   A myVarname  myValname
0  a         B          1
1  b         B          3
2  c         B          5
Copy
Language: English