python - 使用 pandas 和“loc”在 DataFrame(使用 read_excel)中查找值,但不区分大小写
问题描述
我是 Pandas (python) 的初学者。我正在使用它导入 xlsx 文件。
read_excel 函数很好,但是当我搜索字符串值时,它只返回确切的模式(区分大小写)。
我在文档中找不到如何忽略这种情况。我的代码:
def read_food(self):
if len(self.food_filename) > 0 and os.path.exists(self.food_filename):
self.data_frame = pd.read_excel(self.food_filename, skiprows=3, sheet_name=self.sheetname_ingredients, usecols='B,D,G,J', names=['name', 'food_ingredient_for_net_weight', 'foodges_ingredient_for_ingested_weight', 'food_transport_ingredient_weight'], index_col=None, header=None, dtype={'name':str, 'food_ingredient_for_ingested_weight':float, 'food_ingredient_for_ingested_weight':float, 'food_transport_ingredient_weight':float})
else:
raise Exception('[read_food] : food filename/file not exists')
但是,当我用那个搜索一个值时:
return self.data_frame.loc[self.data_frame['name'] == ingredient]
只有具有确切大小写的值才会返回...... :(
请问你有什么想法吗?谢谢
F。
解决方案
推荐阅读
- javascript - 使用 javascript 将元素定位更改为绝对位置时出错
- python - 如何在 python 中比较两个 excel 工作簿?
- google-apps-script - 如何在 GOOGLE Forms 中自动选择日期
- azure-data-explorer - kusto 查询语言 - 将参数值传递给用户定义的函数
- c++ - DX12 初始化失败 VS2019
- mysql - 如何为具有数据类型 Json 的列的 MySQL 编写选择查询?
- vb.net - “&”符号的转义字符是什么?对于 vb.net
- javascript - VSCode:TS/JS 语言功能禁用语法高亮
- ssh - 有没有办法在 PyCharm 中分离正在运行的远程 ssh 脚本?
- php - 使用 post 方法重定向到路由