I have the following pandas dataframe:
import pandas as pd
df = pd.DataFrame([[1, 100, 300, 250],
[2, 475, 200, 0],
[3, 125, 365, 100]], columns=['Client_ID', 'Purchase 1', 'Purchase 2', 'Purchase 3'])
╔═══════════╦════════════╦════════════╦════════════╗
║ Client_ID ║ Purchase 1 ║ Purchase 2 ║ Purchase 3 ║
╠═══════════╬════════════╬════════════╬════════════╣
║ 1 ║ 100 ║ 300 ║ 250 ║
║ 2 ║ 475 ║ 200 ║ 0 ║
║ 3 ║ 125 ║ 365 ║ 100 ║
╚═══════════╩════════════╩════════════╩════════════╝
I want to transpose that table as follows:
╔═══════════╦═══════════╗
║ Client_ID ║ Purchases ║
╠═══════════╬═══════════╣
║ 1 ║ 100 ║
║ 1 ║ 300 ║
║ 1 ║ 250 ║
║ 2 ║ 475 ║
║ 2 ║ 200 ║
║ 2 ║ 0 ║
║ 3 ║ 125 ║
║ 3 ║ 365 ║
║ 3 ║ 100 ║
╚═══════════╩═══════════╝
I've tried df.T but didn't work and I don't want to use a for loop. Is there a way to acchieve this?