October 2019
Beginner to intermediate
674 pages
16h 43m
English
The melt function enables us to transform a DataFrame by designating some of its columns as ID columns, ensuring they remain as columns with the remaining non-ID columns treated as variable columns and are pivoted and become part of a name-value two-column scheme. ID columns uniquely identify a row in a DataFrame.
The names of those non-ID columns can be customized by supplying the var_name and value_name parameters. The use of melt is perhaps best illustrated by an example, as follows:
In [385]: from pandas.core.reshape import melt
In [401]: USIndexDataDF[:2]
Out[401]: TradingDate Nasdaq S&P 500 Russell 2000 DJIA
0 2014/01/30 4123.13 1794.19 1139.36 15848.61
1 2014/01/31 4103.88 1782.59 1130.88 15698.85
In ...Read now
Unlock full access