2
2

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 1 year has passed since last update.

Pandasで忘れがちな処理メモ

Posted at

加筆修正していきます。
最近Pandas使ってませんが・・・

Seriesから値を取り出す

column1がfooに一致したcolumn2の値を取り出す。

df.query("column1 = 'foo'")["column2"].item()

GroupByして上位n件を抽出

column1に対してGroubByし、column2の値が上位n件であるレコードのみ抽出する。

sorted_df = df.sort_values(by="column2", ascending=False) # 降順
groupby_df = sorted_df.groupby("column1").head(n)
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?