I am currently working on a pandas problem and I would like to know whether there is an easy fix for this problem.
I do have pandas tables that always have a format that looks like this:
df = pd.DataFrame({'A':[1,2,np.nan,np.nan,3],'B':[2,3,np.nan,5,2],'C':[2,3,7,5,9],'D':[1,2,3,np.nan,np.nan]} )
This dataframe should be transformed to:
df = pd.DataFrame({'A':[1,2,7,5,3],'B':[2,3,3,5,2],'C':[2,3,np.nan,np.nan,9],'D':[1,2,np.nan,np.nan,np.nan]} )
This means that all the values in the columns need to be shifted to the left as much as possible. (The first column first needs to be filled, followed by the second one, etc.) Is there an easy solution to do this?
Many thanks in advance.