import pandas as pd
STYLES = {'APA': '@{author} ({year}). {title}. {journal}.',
'MLA': '{author}. "{title}" {journal} ({year}).'}
def format_citation(ref, style):
template = STYLES.get(style, STYLES['APA'])
return template.format(**ref)
refs = pd.read_csv('references.csv')
refs['citation'] = refs.apply(lambda r: format_citation(r, r['style']), axis=1)
refs.to_csv('bibliography.csv', index=False)
print(f'Formatted {len(refs)} references')