I have a dataframe that looks like below
df = pd.DataFrame({'person_id': [101,101,101,101,202,202],
'person_type':['A','A','B','C','D','B'],
'course_id':[121,123,135,137,140,143],
'dep_id':[np.nan,Z12,np.nan,B12,np.nan,D12})
I would like to position shift by 1 cell to the right if there is NA in the column dep_id.
I tried the below but it wasn't working
l = list(np.arange(0,len(df.columns) -1))
np.where(df['dep_id'].isna(), l.insert(0,-1))
df.iloc[:,l]
Any efficient and elegant approach to shift column position on big data?
For example, I expect my output to be like as shown below
