There’s probably a slicker way to do this but this works:
def reindex_by_date(df):
dates = pd.date_range(df.index.min(), df.index.max())
return df.reindex(dates).ffill()
df.groupby('id').apply(reindex_by_date).reset_index(0, drop=True)
More Related Contents:
- how to calculation cost time [closed]
- GroupBy pandas DataFrame and select most common value
- String concatenation of two pandas columns
- Reshape wide to long in pandas
- How do I create test and train samples from one dataframe with pandas?
- pandas groupby sort within groups
- How to create a large pandas dataframe from an sql query without running out of memory?
- How do convert a pandas dataframe to XML?
- How to add hovering annotations to a plot
- Sort a pandas dataframe series by month name
- Count frequency of values in pandas DataFrame column
- Strip / trim all strings of a dataframe
- How to iterate over consecutive chunks of Pandas dataframe efficiently
- How to flatten multilevel/nested JSON?
- Neural Network LSTM input shape from dataframe
- Joining pandas DataFrames by Column names
- Diff of two Dataframes
- Apply function to pandas DataFrame that can return multiple rows
- Write to StringIO object using Pandas Excelwriter?
- Scikit Learn OneHotEncoder fit and transform Error: ValueError: X has different shape than during fitting
- “Anti-merge” in pandas (Python)
- Pandas – write Multiindex rows with to_csv
- Writing to a file on SFTP server opened using Paramiko/pysftp “open” method is slow
- Select row from a DataFrame based on the type of the object(i.e. str)
- How to annotate a seaborn barplot with the aggregated value
- Changing certain values in multiple columns of a pandas DataFrame at once
- Round float columns in pandas dataframe
- Converting PANDAS dataframe from monthly to daily
- Pandas datetimes with different formats in the same column
- Get max value from row of a dataframe in python [duplicate]