这有效(使用 Pandas 12 开发)
table2=table[table['SUBDIVISION'] =='INVERNESS']
然后我意识到我需要使用“开始于”来选择字段,因为我错过了一堆。因此,根据 Pandas 文档,我尽可能地遵循我尝试过
criteria = table['SUBDIVISION'].map(lambda x: x.startswith('INVERNESS'))
table2 = table[criteria]
并得到 AttributeError: 'float' object has no attribute 'startswith'
所以我尝试了另一种结果相同的语法
table[[x.startswith('INVERNESS') for x in table['SUBDIVISION']]]
参考http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing 第 4 节:Series 的列表推导和 map 方法也可用于生成更复杂的标准:
我错过了什么?