Javatpoint Logo
Javatpoint Logo

Pandas melt()

The Pandas.melt() function is used to unpivot the DataFrame from a wide format to a long format.

Its main task is to massage a DataFrame into a format where some columns are identifier variables and remaining columns are considered as measured variables, are unpivoted to the row axis. It leaves just two non-identifier columns, variable and value.



  • frame: It refers to the DataFrame.
  • id_vars[tuple, list, or ndarray, optional]: It refers to the columns to use as identifier variables.
  • value_vars[tuple, list, or ndarray, optional]: Refers to columns to unpivot. If it is not specified, use all columns that are not set as id_vars.
  • var_name[scalar]: Refers to a name to use for the 'variable' column. If it is None, it uses or 'variable'.
  • value_name[scalar, default 'value']: Refers to a name to use for the 'value' column.
  • col_level[int or string, optional]: It will use this level to melt if the columns are MultiIndex.


It returns the unpivoted DataFrame as the output.



      Name    Language     Age
0     Parker    Python     22
1     Smith     Java       30
2     John      C++        26



       A    myVarname    myValname
0      p      C            56                
1      q      C            62                
2      r      C            42                

Next TopicDataFrame.merge()

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA