将文件转换为.bib的更好方法

2024-05-23 17:28:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有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

Tags: 文件csvfromimportpandasdatarecordauthors