1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

searchsortedの使い方

Last updated at Posted at 2020-08-13

#1 この記事は何?
要素が順番に並んだ配列に対して、ある要素を挿入したい場合に挿入すべき場所を取得したい。

#2 使用例

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)
105.JPG
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?