报错:TypeError: invalid type comparison,百度试了几个方法还是不行,请问这怎么解决。

要求:使用loc,和 iloc,实现条件切片读取数据源“meal_order_detail.xlsx"或"meal_order_detaill.aql",使用条件表达式,返回某一特定条件下的所有值。


import pandas as pd

detail = pd.read_excel('D:/AAA学习/数据分析/2022.11.9/meal_order_detail.xlsx')
order_id = detail['order_id']
dishes_name = detail.dishes_name
dishes_name1 = detail.loc[:, 'dishes_name']
dishes_name2 = detail.iloc[:, 3]
orderDish1 = detail.loc[:, ['order_id', 'dishes_name']]
orderDish2 = detail.iloc[:, [1, 3]]
# loc内部传入表达式
print('detail中order_id为458的dishes_name为: \n', detail.loc[detail['order_id'] == '1', ['order_id', 'dishes_name']])

img


请问这怎么解决

用数据库却可以,这是为什么呢


import pandas as pd
import numpy
from sqlalchemy import create_engine
engine = create_engine('mysql+pymysql://root:root@127.0.0.1:\
3306/testdb?charset=utf8')
detail = pd.read_sql_table('meal_order_detail1',con = engine)
order_id = detail['order_id']
dishes_name = detail.dishes_name
print('detail中order_id为458的dishes_name为: \n', detail.loc[detail['order_id']=='458',['order_id','dishes_name']])
print('detail中order_id为458的第1,5列数据为: \n', detail.iloc[(detail['order_id']=='458').values,[1,5]])

img

没有人的话,不妨俺来试试