我是python的新手,并希望使用bio软件包中的entrez系统从pubmed中提取摘要。我得到了电子搜索,以提供我的UID(存储在中my_list_ges),也可以使用efetch下载条目。但是现在,结果是字典列表,条目看起来像字典,但我无法访问它们:
Entrez.email= "my-email@provider.sth"
handle=Entrez.efetch(db="pubmed",id=my_list_ges[0],rettype="null",retmode="xml")
record = Entrez.read(handle)
abstract=record["Abstract"]
handle.close()
Run Code Online (Sandbox Code Playgroud)
结果是TypeError:
TypeError: list indices must be integers, not str
Run Code Online (Sandbox Code Playgroud)
KeyError当尝试'Abstract'从第一条记录中检索时,我得到一个:
>>> record[0]["Abstract"]
KeyError: 'Abstract'
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为在电子搜索的结果中,我可以通过字典轻松访问我的UID
record [0]的结构为:
{u'MedlineCitation': DictElement({
u'OtherID': [],
u'OtherAbstract': [],
u'CitationSubset': ['IM'],
u'KeywordList': [],
u'DateCreated': {u'Month': '03', u'Day': '17', u'Year': '2016'},
u'SpaceFlightMission': [],
u'GeneralNote': [],
u'Article':
DictElement({
u'ArticleDate': [
DictElement({u'Month': '03', u'Day': '16', u'Year': '2016'}, attributes={u'DateType': u'Electronic'})],
u'Pagination': {u'MedlinePgn': 'e0151666'},
u'AuthorList': ListElement([
DictElement({
u'LastName': "O'Neill",
u'Initials': 'KE',
u'Identifier': [],
u'AffiliationInfo': [{
u'Affiliation': 'MRC …Run Code Online (Sandbox Code Playgroud) 我想根据相应的字符串(基于字典)在我的绘图 xaxis 中使用不同的颜色显示我的刻度文本。是否有一个功能可以做到这一点,也许是通过 HTML 编码?
ticktext = ['<font color="red">{}</font> '.format(x) for x in ticktexts]
Run Code Online (Sandbox Code Playgroud)
不起作用,它将 html 字符串提供给标签。
我想将pandas DataFrame的索引用作seaborn的x值,并引发值错误。一个小测试示例:
import pandas as pd
import seaborn as sns
sns.lineplot(x='index',y='test',hue='test2',data=pd.DataFrame({'test':range(9),'test2':range(9)}))
Run Code Online (Sandbox Code Playgroud)
它提出:
ValueError: Could not interpret input 'index'
Run Code Online (Sandbox Code Playgroud)
不能将索引用作x值?我究竟做错了什么?Python 2.7,Seaborn 0.9
使用注释时,我尝试在绘图中为文本添加下划线。我使用添加注释
import plotly.graph_objects as go
g = go.FigureWidget(make_subplots(rows=1,cols=1))
g.update_layout(annotations=[dict(text='my text')]) #plus any other parameters
Run Code Online (Sandbox Code Playgroud)
是否有一个选项(也许在注释字典中?)带有下划线的文本?
谢谢!
我处理数据,对于某些示例,数据是有问题的。Python 提出了一个
ValueError:残差在初始点不是有限的。
是否有可能仅通过消息捕获值错误"Residuals are not finite in the initial point."?我试过:
try:
[code that could raise the error]
except Exception as e:
if e=='ValueError(\'Residuals are not finite in the initial point.\')':
[do stuff I want when the Residuals are not finite]
else:
raise e
Run Code Online (Sandbox Code Playgroud)
但它仍然一直引发错误。有没有办法实现我想象的样子?
谢谢
我知道这个主题的变体已经在别处讨论过,但其他线程都没有帮助.
我想将一个字符串从python移交给sql.然而,可能会发生撇号(')出现在字符串中.我想用反斜杠逃脱它们.
sql = "update tf_data set authors=\'"+(', '.join(authors).replace("\'","\\\'"))+"\' where tf_data_id="+str(tf_data_id)+";"
Run Code Online (Sandbox Code Playgroud)
但是,这总是会\\'在我的字符串中给出.因此,反斜杠本身被转义,并且sql语句不起作用.
有人可以帮助我,或者让我替代我这样做的方式吗?谢谢
python ×6
plotly ×2
axis-labels ×1
biopython ×1
exception ×1
formatting ×1
pandas ×1
plot ×1
pubmed ×1
pymysql ×1
python-2.7 ×1
raise ×1
seaborn ×1
str-replace ×1
text ×1
try-catch ×1
underline ×1
valueerror ×1