我有 CSV 文件、文本文件和 Word 文件,其中包含大量要导出到 .bib 文件的参考书目,最好使用我定义的自定义顺序。
我想知道的是,使用 Python 将此信息转换为 .bib 文件的最佳方法是什么?
是否将文本转换为 XML,然后再转换为 .bib?还是加载 CSV 文件并遍历列并逐列写入?
我已经编写了一个用于加载 CSV 并将每一列作为列表的脚本,但是要转换为 .bib 我无法解决。
这是我汇总的代码:
import csv
import pandas
import bibtexparser
from bibtexparser.bparser import BibTexParser
from bibtexparser.customization import *
colnames = ['AUTHORS', 'TITLE', 'EDITOR']
data = pandas.read_csv('file.csv', names=colnames, delimiter =r";", encoding='latin1')
list1 = list(data.AUTHORS)
def customs(record):
record = type(record)
record = author(record)
record = editor(record)
return record
with open('123.bib','w') as bibtex_file:
parser = BibTexParser()
parser.customization = customs