python - 修改 DataFrames 的切片:在 pandas 中使用什么来代替 .ix
问题描述
当我的应用程序崩溃时,我正在遍历 Pandas 中的 DataFrame。我必须从操作的最后一个索引开始对数据进行一些清理。我最终使用了这段代码:
df.ix[start_index:,["col"]] = ""
在我收到弃用警告后不久。但是,我花了很多时间寻找可以使用哪些功能来实现最终结果,.ix
这是我唯一找到的东西。
将来,我将如何实现这样的目标?
解决方案
有 2 种可能的解决方案 - 使用DataFrame.iloc
for 替换位置,也使用按列名称位置替换Index.get_loc
:
df.iloc[start_index:,[df.columns.get_loc("col")]] = ""
或者您可以通过具有索引索引值的标签选择DataFrame.loc
:
df.loc[df.index[start_index]:,["col"]] = ""
推荐阅读
- dependency-injection - 组合根不知道的接口的依赖注入
- html - bootstrap carosel don't works
- bash - 如何将文件名通过管道传输到 ffmpeg 命令中?
- java - Use Spring Beans In Micronaut Applications
- .htaccess - Converting .htaccess to lighttpd for a subdirectory
- sql - 在 QGIS 中为属性搜索表找到正确的 SQL 表达式
- go - How to build extensions to existing packages idiomatically
- scala - polymorphic dispatch from object-oriented programming with pattern matching
- r - 如何在 R 中舍入数据帧的数字以保留总和?
- python - 如何在 python 中修复“IndexError:单个位置索引器越界”?