下面的查询工作并返回一个数据帧子集,其中只包含包含James记录的行。你知道吗
pat_db.query('pat_medical_records == "James"')
但是,我需要检索成千上万患者的信息。因此,我试图分配一个变量名“a”,并将其传递给上面的行。在这里我得到错误。你知道吗
a = James
pat_db.query('pat_medical_records == a')
UndefinedVariableError: name 'a' is not defined
然后我尝试手动分配“a”:
a = "James"
pat_db.query('pat_medical_records == a')
UndefinedVariableError: name 'a' is not defined
我错过了什么?你知道吗
试试这个:
你可能想读this great Pandas documentation with lots of useful examples
演示:
可以使用
str.format
指定要插入的占位符字符串:相关问题 更多 >
编程相关推荐