To process data in CSV, Excel, SQL (and many other formats), I prefer to use the Pandas module:
import pandas as pd filename = r'D:\download\dump.xlsx' # parse Excel file into a DataFrame df = pd.read_excel(filename, usecols="B,E") # get rid of `prefix_` in the 'NAME' column df['NAME'] = df['NAME'].str.partition('_', expand=False).str[-1] # parse a string "address/image:number" into two columns ['IMAGE','NUM'] df[['IMAGE','NUM']] = df['IMAGE'].str.replace(r'.*\/', '').str.split(':', expand=True) # add an empty column, which is needed for showing a coma # at the end of each line in the CSV file df['EMPTY'] = "" # save DF as a CSV file df.to_csv(r'd:/temp/result.csv', header=None, index=False)
PS for reading Excel files Pandas by default uses the xlrd module.
Result:
In [28]: from pathlib import Path In [29]: print(Path(r'd:/temp/result.csv').read_text()) directory_preview_v2,directory-service,28.0.0, find_cli,find-cli,9.1.0,