I want to get the place to insert when I want to insert an element in an array of elements arranged in order.
test.py
df = pd.DataFrame({"A":[1,3,7,8,9]})
print(df)
print(df.A)
a0=df.A.values.searchsorted(5, side='right') # a0 = 2
a1=df.A.values.searchsorted(3, side='right') # a1 = 2
a2=df.A.values.searchsorted(3, side='left') # a2 = 1
print(a0)
print(a1)
print(a2)
Recommended Posts