搜索熊猫列之间的范围内的值(不是日期列,没有SQL)
事先感谢您的帮助。我有两个数据框 如下所示。我需要根据尺寸框架中的信息在销售框架中创建列类别。它应该检查该产品和返回组的最小值内的产品和最大尺寸。可以在熊猫中做吗?不是SQL。我认为合并和加入方法在这里无法使用。
size=pd.DataFrame({"Min Size":[30,41,40],
"Max Size":[40, 60, 50],
"Category":['small', 'big', "medium"],
"Product":['Apple', 'Apple', "Peach"]})
sold=pd.DataFrame({"Purchase_date":["20/01/2020", "18/02/2020", "01/06/2020"],
"Size":[35, 45, 42],
"Category":["small","big","medium"],
"Product":['Apple', 'Peach', "Apple"]})
thanks in advance for help. I have two dataframes
as given below. I need to create column category in sold frame based on information in size frame. It should check siz of product within Min and Max sizes for this product and return group. Is it possible to do it in pandas? not SQL. I think merge and join method will not work here.
size=pd.DataFrame({"Min Size":[30,41,40],
"Max Size":[40, 60, 50],
"Category":['small', 'big', "medium"],
"Product":['Apple', 'Apple', "Peach"]})
sold=pd.DataFrame({"Purchase_date":["20/01/2020", "18/02/2020", "01/06/2020"],
"Size":[35, 45, 42],
"Category":["small","big","medium"],
"Product":['Apple', 'Peach', "Apple"]})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
熊猫中的连接条件必须完全匹配。它没有SQL中的...和... 子句之间的
。
您可以使用numpy广播将中的每一行比较与
size
中的每个行进行比较,并进行匹配的过滤器:Joining condition in pandas must be exact match. It doesn't have the
BETWEEN ... AND ...
clause like in SQL.You can use numpy broadcast to compare every row in
sold
to every row insize
and filter for a match: