縦1列だと使いにくそうなので、縦横のデータフレームにしてみました。
出力例
python
1>>> print(df_counts)
2 push1_start_date push2_start_date push3_start_date push4_start_date push5_start_date
3dates
42021-04-29 0 0 0 0 0
52021-04-30 1 0 0 0 0
62021-05-01 1 0 0 0 1
72021-05-02 0 0 0 0 0
82021-05-03 1 0 0 2 0
92021-05-04 0 0 0 0 0
102021-05-05 1 0 0 0 1
112021-05-06 2 0 1 0 0
122021-05-07 0 0 0 0 0
132021-05-08 0 1 0 0 0
142021-05-11 0 3 1 1 1
152021-05-12 1 1 1 0 2
162021-05-13 0 0 1 0 0
172021-05-14 1 0 0 1 2
182021-05-15 3 1 1 3 0
192021-05-16 0 2 0 0 0
202021-05-17 0 1 0 2 0
212021-05-18 1 0 2 2 3
222021-05-19 0 1 0 0 0
232021-05-20 2 2 0 0 2
242021-05-21 0 0 0 0 0
252021-05-22 0 2 2 2 0
262021-05-23 0 0 1 2 1
272021-05-24 0 0 1 0 1
282021-05-25 0 0 0 1 1
292021-05-26 1 0 0 0 1
302021-05-27 1 0 1 0 0
312021-05-28 1 0 0 0 0
322021-05-29 0 1 0 0 0
332021-05-30 1 0 1 0 0
342021-05-31 0 2 0 0 0
352021-06-01 0 1 1 1 1
362021-06-02 1 1 0 2 0
372021-06-03 0 0 1 1 1
382021-06-04 0 2 0 0 1
392021-05-12 1 1 1 0 2
402021-05-13 0 0 1 0 0
412021-05-14 1 0 0 1 2
422021-05-15 3 1 1 3 0
432021-05-16 0 2 0 0 0
442021-05-17 0 1 0 2 0
452021-05-18 1 0 2 2 3
462021-05-19 0 1 0 0 0
472021-05-20 2 2 0 0 2
482021-05-21 0 0 0 0 0
492021-05-22 0 2 2 2 0
502021-05-23 0 0 1 2 1
512021-05-24 0 0 1 0 1
元データ
python
1>>> print(dates)
2>>> print(dates)
3['2021-04-29', '2021-04-30', '2021-05-01', '2021-05-02', '2021-05-03', '2021-05-04', '2021-05-05', '2021-05-06', '2021-05-07', '2021-05-08', '2021-05-11', '2021-05-12', '2021-05-13', '2021-05-14', '2021-05-15', '2021-05-16', '2021-05-17', '2021-05-18', '2021-05-19', '2021-05-20', '2021-05-21', '2021-05-22', '2021-05-23', '2021-05-24', '2021-05-25', '2021-05-26', '2021-05-27', '2021-05-28', '2021-05-29', '2021-05-30', '2021-05-31', '2021-06-01', '2021-06-02', '2021-06-03', '2021-06-04', '2021-05-12', '2021-05-13', '2021-05-14', '2021-05-15', '2021-05-16', '2021-05-17', '2021-05-18', '2021-05-19', '2021-05-20', '2021-05-21', '2021-05-22', '2021-05-23', '2021-05-24']
4>>> print(df)
5 push1_start_date push2_start_date push3_start_date push4_start_date push5_start_date
60 <NA> 2021-06-02 2021-05-06 <NA> 2021-05-20
71 2021-05-26 <NA> <NA> 2021-05-14 <NA>
82 <NA> 2021-05-16 <NA> 2021-05-15 2021-05-01
93 <NA> <NA> 2021-06-03 2021-05-03 <NA>
104 2021-05-18 2021-05-11 2021-05-12 2021-05-11 2021-05-23
115 <NA> 2021-05-22 <NA> 2021-05-17 2021-05-18
126 2021-05-06 <NA> 2021-05-15 <NA> <NA>
137 <NA> <NA> <NA> <NA> 2021-05-11
148 2021-05-30 2021-06-04 2021-05-18 2021-06-02 2021-05-18
159 2021-05-01 2021-05-16 <NA> 2021-05-25 2021-05-14
1610 2021-05-12 <NA> <NA> <NA> 2021-05-24
1711 2021-05-06 2021-05-17 2021-05-24 2021-05-23 2021-05-18
1812 <NA> <NA> 2021-06-01 2021-05-18 2021-06-03
1913 <NA> 2021-05-11 <NA> 2021-06-02 2021-05-14
2014 2021-05-28 2021-06-01 2021-05-11 <NA> 2021-06-01
2115 <NA> 2021-05-11 <NA> 2021-05-17 <NA>
2216 2021-05-15 2021-05-15 <NA> <NA> 2021-06-04
2317 2021-05-14 2021-05-31 2021-05-30 <NA> <NA>
2418 2021-04-30 2021-05-08 <NA> 2021-05-03 2021-05-26
2519 2021-05-20 <NA> 2021-05-23 2021-05-15 <NA>
2620 <NA> 2021-05-29 2021-05-27 2021-05-15 2021-05-05
2721 <NA> 2021-05-22 <NA> <NA> 2021-05-12
2822 2021-05-20 2021-05-20 <NA> 2021-06-01 2021-05-25
2923 <NA> 2021-05-31 <NA> 2021-05-18 <NA>
3024 2021-05-05 2021-06-04 2021-05-22 2021-05-22 <NA>
3125 2021-05-03 2021-05-20 2021-05-18 <NA> <NA>
3226 2021-06-02 2021-05-12 <NA> 2021-05-22 2021-05-20
3327 2021-05-27 <NA> 2021-05-13 2021-06-03 <NA>
3428 2021-05-15 2021-05-19 <NA> <NA> <NA>
3529 2021-05-15 <NA> 2021-05-22 2021-05-23 2021-05-12
処理
python
1df_dates = pd.DataFrame({'dates': dates})
2
3def count_one_column(df, column, df_dates):
4 df1 = df[[column]].copy()
5 df1['count'] = 1
6 df2 = df1.groupby(column).sum().reset_index()
7 df3 = pd.merge(df_dates, df2,
8 left_on='dates', right_on=column, how='left')
9 df4 = df3.drop(column, axis=1).set_index('dates')
10 df4.columns = [column]
11 df4.fillna(0.0, inplace=True)
12 df5 = df4[column].astype(int)
13 return df5
14
15df_counts = pd.concat([count_one_column(df, column, df_dates) for column in df.columns], axis=1)
16print(df_counts)