【发布时间】:2021-12-16 20:05:11
【问题描述】:
我正在使用以下函数从数据库查询中过滤掉许多文件类型。文件扩展名有大小写变化(例如,Tif、tIF、TIF、tif)。但是,我需要在系统中按原样使用大写进一步查询。
我的解决方案:
- 复制数据帧 (Pandas) 小写(已经完成)。
- 根据两个列表执行过滤器(已经完成)。
- 返回过滤对象在被过滤之前所在位置的索引(索引?)列表。
- 使用索引列表从我的原始列表中删除对象。这会保留我的大写字母并删除正确的项目。
我不知道如何返回原始索引。请帮忙!
变量:
path_list_lowercase
suffixes_unwanted
def index_pos_filtered_paths(path_list_lowercase, suffixes_unwanted):
for [x for x in path_list_lowercase if all(y not in x for y in suffixes_unwanted)]
return path_list_lowercase(x).index(suffixes_unwanted(y))
index_of_filtered_paths_list = index_pos_filtered_paths(path_list_lowercase, suffixes_unwanted)
【问题讨论】:
标签: python pandas list indexing filtering