pandas dataframe 将一行按拆分成多行

需求场景

拆分方法

方法一

df=df.drop('cont', axis=1).join(df['cont'].str.split('/', expand=True).stack().reset_index(level=1, drop=True).rename('tag'))

方法二

df=df['cont'].str.split('/', expand=True).stack().reset_index(level=0).set_index('level_0').rename(columns={0:'tag'}).join(df.drop('cont', axis=1))
原文地址:https://www.cnblogs.com/Jaryer/p/13644331.html