Reputation: 11
I have two dataframes. df_0 is a complete list of dates and df_1 is a generic register indexed by incomplete dates. I need to make a dataframe that has df_0’s complete dates as an index, filled with df_1’s register in the matching dates. For dates without a register entry, I just need to repeat the last date’s register data as a filler. Any ideas on how to make this?
Thanks in advance.
Upvotes: 1
Views: 162
Reputation: 862691
Use DataFrame.reindex
with parameter method
:
df = df_1.reindex(df_0.index, method="ffill")
Upvotes: 2
Reputation: 620
use 'reindex' to expand the df_1 and use 'fillna' to fill in the missed valued.
df_2 = df_1.reindex(df_0.index).fillna(method="ffill")
Upvotes: 0