I have the following DataFrame built:
Movies Cost Tickets 0 1158 0.000000 2.000000 1 1158 0.000000 0.000000 2 1158 0.000000 0.000000 3 1158 0.000000 3.000000 I've used stack() to change my configuration to:
Event 1 0 Movies 1158 1 Cost 0.000000 2 Tickets 2.000000 3 Movies 1158 4 Cost 0.000000 5 Tickets 0.000000 6 Movies 1158 7 Cost 0.000000 8 Tickets 0.000000 9 Movies 1158 10 Cost 0.000000 11 Tickets 3.000000 but this is stacking the data top of each other, I was looking to create a new column with the end goal being:
Event 1 Event 2 Event 3 Event 4 0 Movies 1158 1158 1158 1158 1 Cost 0.000000 0.000000 0.000000 0.000000 2 Tickets 2.000000 0.000000 0.000000 3.000000 here is my current configuration:
df = pd.DataFrame({ 'Tickets': pd.Series(Tickets), 'Movies': pd.Series(Movies), 'Cost': pd.Series(costs)}) print(df) df.columns.name = '' stackEvent3 = df.stack() stackEvent3 = df.stack().reset_index(level=0, drop=True).reset_index(name='Event1') Any guidance is greatly appreciated, thank you!
df.T