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

PandasのGroupbyについて np.sum(), np.sum(), aggもろもろのメモ

Posted at

np.size

カウント値(レコード数)を計算する
(np.count)は存在しない

np.sum

合計値を計算する

df.groupby(['col1','col2'], as_index=false).agg(
    'col_3': np.sum,
    'col_4': np.size)

as_index=falseはgroupybyの['col1','col2']がそのまま出るので、CSVやDBに出力する時にデータとしてそのまま使える。

col1       col2   col3  col4
2023/04/01 tokyo  100   1
2023/04/01 oosaka 200   4
2023/04/01 tokyo  150   2
0
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
0
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?