I tried different options but I always return to the .get_loc
function. I got a big data frame and need to find the row index of a value nearest
or backfill
. The df looks like this:
Date Product Price
0 1/1 NEG 3
1 1/1 NEG 3.3
2 1/1 NEG 5.1
3 1/1 POS 1.4
4 1/1 POS 3.7
5 1/1 POS 3.9
6 1/1 POS 4.6
7 1/2 NEG 1.2
8 ... ... ...
df.columns.get_loc('Price')
gives me 2
for the index of the column 'Price', but I need the index of a special row by section ('Date' and 'Product'), e.g:
df.loc[(df)['Date']=='1/1' & (df['Product']=='NEG')]
now, search Price == 3.4:
pd.Index(df.Price).get_loc(3.4, 'nearest')
This would give me index=1, but it does not work because data is to big, there are multiple '3.4'.
Is there any way to search for the nearest value with certain conditions, like above?