【问题标题】:How do I get the data in between two Column values?如何获取两个 Column 值之间的数据?
【发布时间】:2021-07-23 03:11:25
【问题描述】:

我想获取 df['Instrument'] 列的 'Closed Qty' 和 'Symbol' 之间的数据。请参考图片。 'Closed Qty' 和 'Symbol' 都是 df['Instrument'] 列的值。 所以,我想获取“已关闭数量”和“符号”行之间的所有值,包括“已关闭数量”和“符号”行。

【问题讨论】:

    标签: python python-3.x jupyter-notebook data-analysis data-cleaning


    【解决方案1】:

    你可以试试下面的表达式:

    idx = df.index[np.where((df.index >= df[df['Instrument'] == 'Closed Qty'].index[0]) & (df.index <= df[df['Instrument'] == 'Symbol'].index[0]))]
    df[df.index == idx]
    

    这里(df.index &gt;= df[df['Instrument'] == 'Closed Qty'].index[0]) 查找Closed Qty 下方的行(包括它),表达式(df.index &lt;= df[df['Instrument'] == 'Symbol'].index[0]) 查找Symbol 之前的行(也包括它)。 Numpy where() 结合了这两个表达式,在 Closed QtySymbol 之间找到值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      • 1970-01-01
      • 2019-04-19
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      • 2023-01-12
      相关资源
      最近更新 更多