python - 获取'关键错误:“['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 并寻求一些帮助来刷新以来已经有一段时间了。提前致谢。
解决方案
你需要写成ClientType
这样的字符串
df['ClientType'].unique()
推荐阅读
- ffmpeg - 使ffmpeg从指定的块而不是开始读取m3u8
- c++ - C ++中的电话号码验证?
- json - 使用 JsonReader.setLenient(true) 在改造中的第 1 行第 1 列路径 $ 处接受格式错误的 JSON
- c# - 如何在 ListBox 中转到下一行?
- javascript - 如何呼叫那些拥有更多数据的人?json
- visual-studio-code - 如何将文件夹添加到我在 VS Code 中打开的 git 存储库中?
- sql - SQLite 插入 - 如何在使用参数化值避免语法错误的同时插入任何文本
- javascript - 更改链接颜色
- openssh - 如何在 OpenSSH 中动态允许用户?
- javascript - 在reveal.js中确定内部视口宽度