Q:

Pandas Dataframe Add a value to a new Column based on the previous row limited to the maximum value in that column

It is so hard to learn all the tricks for pandas or working with dataframes.
So I have a df with a certain amount of weeks listed. I wanted to create a metrics table or dataframe that has additional columns added with sequential ascending weeks added only populating the row to the maximum week list in column 'Week'
       Week
 0    201152
 1    201201
 2    201202
 3    201203
 4    201204

The below df is the result i am trying to get to.
       Week  2ndWeek 3rdWeek 4thWeek 5thWeek 
 0    201152  201201  201202  201203  201204
 1    201201  201202  201203  201204
 2    201202  201203  201204  
 3    201203  201204  
 4    201204  

Any ideas?

A:

import pandas as pd
ts = df.Week
for week in range(len(ts) - 1):
    ts = ts.drop(ts.idxmin())
    ts.index = pd.Index(range(len(ts)))
    ts.name = '%s_Week' % week
    df = df.merge(pd.DataFrame(ts), left_index=True,right_index=True, how='outer')

