Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

complete dates pandas per group by

s = (pd.MultiIndex.from_tuples([[x, d]
      for x, y in df.groupby("Id")["Dt"]
      for d in pd.date_range(min(y), max(df["Dt"]), freq="MS")], names=["Id", "Dt"]))

print (df.set_index(["Id", "Dt"]).reindex(s, fill_value=0).reset_index())
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #complete #dates #pandas #group
ADD COMMENT
Topic
Name
5+5 =