如何获取两个列值之间的数据?

How do I get the data in between two Column values?

我想获取列 df['Instrument'] 的 'Closed Qty' 和 'Symbol' 之间的数据。请参考图片。 'Closed Qty' 和 'Symbol' 都是 df['Instrument'] 列的值。 所以,我想获取行 'Closed Qty' 和 'Symbol' 之间的所有这些值,包括行 'Closed Qty' 和 'Symbol'。

您可以尝试以下表达式:

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 >= df[df['Instrument'] == 'Closed Qty'].index[0]) 查找 Closed Qty 下方的行(包括它),表达式 (df.index <= df[df['Instrument'] == 'Symbol'].index[0]) 查找 Symbol 之前的行(也包括它)。 Numpy where() 结合了 Closed QtySymbol.

之间的两个表达式