import os import re import yaml import pandas as pd from glob import glob excel_names = glob('*.xlsx') for excel_name in excel_names: print('processing {}'.format(excel_name)) df = pd.read_excel(excel_name) survey_id, _ = os.path.splitext(excel_name) for i, row in df.iterrows(): beach = row['BEACH'].replace('_', '-').lower() yaml_name = '{}-{}.yaml'.format(survey_id, beach) with open(yaml_name, 'w') as f: f.write(yaml.dump(row.to_dict(), default_flow_style=False))