首页 > 解决方案 > 获取'关键错误:“['None'] 不在索引中

问题描述

我试图从我的数据框中的列中找到不同的唯一值。

df[ClientType].unique()

结果抛出此错误:'Key Error: "['None'] not in index

我使用创建了该列

name_types = client_new.pivot_table(index='Name', values='AccountType', aggfunc=set) 
client_new['ClientType'] = client_new['Name'].apply(lambda x: name_types.loc[x]['AccountType']) 

自从我使用 Python 并寻求一些帮助来刷新以来已经有一段时间了。提前致谢。

标签: pythonfiltering

解决方案


你需要写成ClientType这样的字符串

df['ClientType'].unique()

推荐阅读