'Use python to remove blank cells from column and shift populated cells up

I have this excel file and I would like to delete all blank cells in columns A and shift the populated cells up using python.

Not sure how to do this, any advice? I know I can go into excel and do it manually but I need to automate this process. Multiple files looking just like this will be created, and I need to automate adjusting this so that all those populated cells in column A actually sit next to the rest of the data in B, C, D, E.

enter image description here



Solution 1:[1]

Use pandas to import and modify your excel.

import pandas as pd
df = pd.read_excel('yourfile.xlsx')
df = df.apply(lambda x: pd.Series(x.dropna().values)).fillna(' ')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1