pandas.melt
pandas 3.1.1 · General functions · function
Keep identifier columns and turn measured columns into variable–value rows.
Call syntax
pd.melt(…) Full signature
pd.melt(
frame,
id_vars=None,
value_vars=None,
var_name=None,
value_name='value',
col_level=None,
ignore_index=True,
)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
frame |
Required Positional or keyword |
DataFrame Supply the DataFrame the function processes. |
id_vars |
Optional Positional or keyword Default None |
scalar, tuple, list, or ndarray Select identifier columns that stay intact during a melt. |
value_vars |
Optional Positional or keyword Default None |
scalar, tuple, list, or ndarray Choose the measured columns moved into rows. |
var_name |
Optional Positional or keyword Default None |
scalar, tuple, list, or ndarray Set the output column name for the original measured column labels. |
value_name |
Optional Positional or keyword Default 'value' |
scalar Set the output column name for the measured values. |
col_level |
Optional Positional or keyword Default None |
scalar |
ignore_index |
Optional Positional or keyword Default True |
bool Give the resulting axis new integer labels where supported. |
Returns
DataFrame