如何解决如何获取“pybtex.utils.OrderedCaseInsensitiveDict”的字典键
我正在尝试将 bibtex 文件制作成 CSV 文件。我试过直接使用熊猫:
with open('bibTex.bib') as bibtex_file:
bib_database = bibtexparser.load(bibtex_file)
df = pd.DataFrame(bib_database.entries)
df.to_csv('ref.csv',index=False)
但是由于我的 ,
文件中有很多 .bib
,它无法按我的需要工作,所以我是这样做的:
import pandas as pd
import bibtexparser
from pybtex.database.input import bibtex
#open a bibtex file
parser = bibtex.Parser()
bibdata = parser.parse_file("bibTex.bib")
#loop through the individual references
for bib_id in bibdata.entries:
b = bibdata.entries[bib_id].fields
print(type(b))
它返回一个 <class 'pybtex.utils.OrderedCaseInsensitiveDict'>
我想获取一个通用 python 字典的键,但它不起作用我在文档中找不到任何关于它的内容。
OrderedCaseInsensitiveDict([('title','{The Beck Depression Inventory-II (BDI-II),Beck Hopelessness Scale (BHS),and Beck Scale for Suicide Ideation (BSS).}'),('year','2004'),('month',''),('journal',('booktitle','Comprehensive handbook of psychological assessment,Vol. 2: Personality assessment.'),('publisher','John Wiley & Sons,Inc.'),('address','Hoboken,NJ,US'),('volume',('number',('pages','50--69'),('doi',('isbn','0-471-41612-6 (Hardcover)'),('issn',('url',('note',('abstract',"This chapter describes the Beck Depression Inventory-Second edition (BDI-II),and Beck Scale for Suicide Ideation (BSS). Given that the BDI-II is the most widely used of these measures,coupled with the fact that comprehensive reviews of this revised instrument have yet to appear in the literature,the primary focus of this chapter concerns the examination of the BDI-II. However,the remaining scales that we review are used widely as well,especially in the assessment of depression. Although we do not review the Beck Anxiety Inventory (BAI),which is another of the most commonly used Beck scales,readers are directed to some recent review papers (see Steer & Beck,1997; Wilson,de Beurs,Palmer,& Chambless,1999). We begin with a review of the principal features,test development,psychometric characteristics,research status,and applicability of each of these instruments. We also discuss the limitations of these measures,mention age and cross-cultural factors,highlight accommodations made for persons with disabilities,address legal and ethical issues,and summarize each instrument's current research status. Following this examination,we underscore how these measures may be used in clinical practice. (PsycInfo Database Record (c) 2021 APA,all rights reserved)"),('comment',('eprint',('groups',('keywords','*Beck Depression Inventory,*Hopelessness,*rating Scales,*Suicidal Ideation,Psychometrics,Test Construction'),('owner',('printed',('priority',('qualityassured',('ranking',('readstatus',('relevance',('timestamp','')])
非常感谢:)
解决方法
从 0.23.0 版本开始,OrderedCaseInsensitiveDict 已使用 collections.OrderedDict 实现 所以要获取键和值,您可以使用 .keys() 和 .values() 参见下面的 example:
>>>import pybtex.utils as p
>>>d = p.OrderedCaseInsensitiveDict([
... ('Uno',1),... ('Dos',2),... ('Tres',3),... ])
>>> d
OrderedCaseInsensitiveDict([(u'Uno',(u'Dos',(u'Tres',3)])
>>> list(d.keys())
[u'Uno',u'Dos',u'Tres']
>>> list(d.items())
[(u'Uno',3)]
>>> list(d.values())
[1,2,3]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。