2 つの日時の間のアクティビティをカウントできるようにするための一種のフォローアップの質問として、ここで非常によく答えられています: Create a Pandas dataframe with counts of items spanning a date range
残りの問題は、2 つのテーブルを合計して減算した後、最終月 ['END_DATE'] がゼロを表示することです。これは、すべての項目の終了日がその月またはそれ以前であるため、数学的には正しいのですが、この場合はそれらはその月に少なくともある程度はアクティブでした。END_DATE に 1 か月を追加する方が正しいので、最終月にアクティブであると表示されます (H2 はデータフレームです)。
コードは次のとおりです。
ends = H2['END_DATE'].apply(lambda t: t.to_period(freq='m')).value_counts()
たとえば、ロールフォワードと DateOffset(month=1) を使用しようとしました。日付オフセットの場合:
ends = (H2['END_DATE'].DateOffset(months=1)).apply(lambda t: t.to_period(freq='m')).value_counts()
これは私にこのエラーを与えます:
AttributeError: 'Series' object has no attribute 'DateOffset'