Pandas Pivot Table add subsequent columns then divide by previous column

I have the following pandas pivot table: table = pd.pivot_table(df, index = ‘group’, columns = ‘levels’, values = ‘uid’, aggfunc = ‘count’, margins = True) There are three levels (level 1, level 2, and level 3). Basically I have individuals that progress through these levels, but I want to know what percentage of people make… Read More Pandas Pivot Table add subsequent columns then divide by previous column

convert data elements in data frame via long to wide format using Panda

I have my df as below: df I want to convert into df2 as below: df2 I have been trying with panda, but still not able to achieve my targeted aim. This is my sample code: df = pd.read_excel(‘PathV1.xlsx’) df1 = pd.DataFrame(df, columns=[‘source’]) df1[[‘target’]] = pd.DataFrame(df1[‘source’].str.split(‘:’).tolist()) df1[‘index’] = df1.index// 3 df2 = df1[[‘source’, ‘target’, ‘index’]].pivot(columns=’source’,… Read More convert data elements in data frame via long to wide format using Panda