不再支持将类似列表的标签传递给.loc或[]且缺少任何标签 [英] Passing list-likes to .loc or [] with any missing labels is no longer supported

查看:48
本文介绍了不再支持将类似列表的标签传递给.loc或[]且缺少任何标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用指定的列创建一个修改的数据框.我尝试了以下操作,但抛出错误不再支持将缺少列表的标签传递给.loc或[]并且缺少任何标签"

I want to create a modified dataframe with the specified columns. I tried the following but throws the error "Passing list-likes to .loc or [] with any missing labels is no longer supported"

# columns to keep
filtered_columns = ['text', 'agreeCount', 'disagreeCount', 'id', 'user.firstName', 'user.lastName', 'user.gender', 'user.id']
tips_filtered = tips_df.loc[:, filtered_columns]

# display tips
tips_filtered

谢谢

推荐答案

Pandas似乎已弃用这种索引方法.根据他们的

It looks like Pandas has deprecated this method of indexing. According to their docs:

此行为已弃用,并将显示警告消息到本节.推荐的替代方法是使用.reindex()

This behavior is deprecated and will show a warning message pointing to this section. The recommended alternative is to use .reindex()

使用新的推荐方法,您可以使用以下方法过滤您的列:

Using the new recommended method, you can filter your columns using:

tips_filtered = tips_df.reindex(columns = filtered_columns).

注意:要重新索引行,您可以使用 reindex(index = ...)(更多信息

NB: To reindex rows, you would use reindex(index = ...) (More information here).

这篇关于不再支持将类似列表的标签传递给.loc或[]且缺少任何标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆