Home > Software design >  Openpyxl with Python - How to delete spaces and replace with commas
Openpyxl with Python - How to delete spaces and replace with commas

Time:07-30

I am still new to python and have been asked to reformat a large spreadsheet. Trying to follow this system: enter image description here


import pandas as pd


def cell_strip(cell):
    lines = str(cell).splitlines()
    filter_v_lines = [i.strip() for i in lines if i.strip()]
    final_v_str = '\n'.join(filter_v_lines)
    return final_v_str


file_path = "strip.xlsx"
df = pd.read_excel(file_path)
print(df)

df_1 = df.applymap(cell_strip)
df_1.to_excel('new.xlsx',index=False)
print(df_1)

  • Related