【问题标题】:Pandas: How to find out if data from one table falls within the range of a second table熊猫:如何找出一个表中的数据是否在第二个表的范围内
【发布时间】:2018-05-14 17:27:56
【问题描述】:

我们一天有两个订单: Time of two payments in one day

以及使用所有应用程序的时间 Time of using all applications

问题:给定第一个表的时间,然后下订单,我们如何确定第二个表中的时间段?

【问题讨论】:

  • 不要将数据帧和代码作为图像发布。将它们作为文本发布在您的问题中。
  • 好的,下次发不带图的。感谢您的建议:)

标签: python pandas dataframe


【解决方案1】:

您可以为每个订单确定当时使用了哪些应用程序。显然,当时可能有不止一个应用程序在运行。假设您的订单存储在一个名为 order_df 的数据框中,而应用程序信息存储在另一个名为 application_df 的数据框中。然后您可以遍历所有订单并检查哪些应用程序正在运行(将结果存储在字典中):

order_map = {}
for ix, it in order_df.iterrows():
    order_id = it['OrderId']
    order_time = it['Time']
    condition = (application_df['StartTime'] <= order_time) & (application_df['EndTime'] >= order_time)
    order_map[order_id] = application_df[condition]['ApplicationID'].values

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-09
    • 2021-03-28
    • 2019-07-04
    • 2022-10-04
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 2012-11-05
    相关资源
    最近更新 更多