请您参考如下方法:
试试这个来获取没有租户 ID 的帐户名称列表:
res = df.loc[df['Tenant ID'].isnull(), 'Account Name'].tolist()
或者,为租户 ID 为空的行过滤数据框:
df = df.loc[df['Tenant ID'].isnull(), :]
解释
.loc访问器允许您通过 bool 数组或标签指定行和列。- 对于行过滤器,我们通过
pd.Series.isnull使用 bool 数组来识别 Tenant Id 为空的行。 - 对于列过滤器,我们可以使用'Account Name' 并通过
pd.Series.tolist输出到列表。
