0
I have to find the rows in the dataframe where those conditions are met:
OrderDirection is “SELL”, then the Price of “PRINCIPAL” element in OrderType with its corresponding “TRADE” element in OrderStatus column should be greater than the Price of the “AGENCY” element in OrderType column with its corresponding “NEW” element in OrderStatus column.
I got the error: KeyError: 'the label [True] is not in the [index]'
How can I solve it?
Below the code:
def selection_sort(nums):
# This value of i corresponds to how many values were sorted
for i, row in nums.iterrows():
# We assume that the first item of the unsorted segment is the smallest
lowest_value_index = i
# This loop iterates over the unsorted items
for j in (i + 1, range(len(nums.Price))):
if row.loc[row['Order Type'] == 'Agency', 'Price'].iloc[lowest_value_index] > row.loc[row['Order Type'] == 'Principal', 'Price' ].iloc[j]:
lowest_value_index = j
# Swap values of the lowest unsorted element with the first unsorted
# element
row.loc[row['Order Type'] == 'Principal', 'Price'].iloc[i], row.loc[row['Order Type'] == 'Agency', 'Price'].iloc[lowest_value_index] = row.loc[row['Order Type'] == 'Agency' , 'Price'].iloc[lowest_value_index], row.loc[row['Order Type'] == 'Principal', 'Price'].iloc[i]
selection_sort(data19)