pd.melt
一、函數
pd.melt( ['frame', 'id_vars=None', 'value_vars=None', 'var_name=None', "value_name='value'", 'col_level=None']
參考官方文檔
melt: V (使)熔化,融化
pd.melt將多列數據進行融合。
二、參數
id_vars: tuple, list, or ndarray, optional
用作標識符的列
value_vars:tuple, list, or ndarray, optional
如果沒有指定,是data列中除去id_vars后剩下的列
var_name: scalar
‘variable’ 列的命名名稱. 如果沒有指定,則使用frame.columns.name 或者 ‘variable’.
value_name: scalar
‘value’ 列的命名名稱. 如果沒有指定,則使用frame.columns.name 或者 ‘value’.
col_level: int or str, optional
If columns are a MultiIndex then use this level to melt.
ignore_indexbool, default True
If True, original index is ignored. If False, the original index is retained. Index labels will be repeated as necessary.
New in version 1.1.0.
三、實例
c = {'col1': list(map(chr,range(97,100,1))), 'col2':list(range(10,13,1)),'col3':list(range(20,23,1))} c = pd.DataFrame(c) c
默認情況下,將所有的列都加入到variable
總結
- 上一篇: seaborn.distplot()
- 下一篇: seaborn.FacetGrid