通常,我想線性化一個數(shù)據(jù)框。例如, a b 1 l m2 n o到columns index value a 1 l b 1 m a 2 n b 2 o 我使用此自定義代碼來線性化數(shù)據(jù)框。import pandas as pddef unstack2df(df,coln='columns',idxn='index',col='value'): if df.columns.name is None: df.columns.name=coln if df.index.name is None: df.index.name=idxn df=df.unstack() df.name=col return pd.DataFrame(df).reset_index()我想知道熊貓中是否有內(nèi)置模塊可以做到這一點(diǎn)。
熊貓函數(shù)線性化數(shù)據(jù)框
繁華開滿天機(jī)
2021-03-30 21:18:39