First, move the non-date columns in to the index, then use replace and reset_index:
df = df.set_index('CashFlows')
df = df.rename(columns=lambda x: 'year_'+str(x.year))
More Related Contents:
- How to provide a reproducible copy of your DataFrame with to_clipboard()
- How to replace NaNs by preceding or next values in pandas DataFrame?
- Find column whose name contains a specific string
- Calculate average of every x rows in a table and create new table
- Conditionally fill column values based on another columns value in pandas
- How to deal with multi-level column names downloaded with yfinance
- Rolling Mean on pandas on a specific column
- Pandas deleting row with df.drop doesn’t work
- Count number of words per row
- What is the fastest and most efficient way to append rows to a DataFrame?
- Updating a value in a pandas dataframe in an iterrows loop
- append dictionary to data frame
- Python pandas: how to remove nan and -inf values
- Check if rows in one dataframe exist in another dataframe
- How to convert string representation of dictionary in Pandas DataFrame to a new columns?
- Python Pandas – Lookup a variable column depending on another column’s value
- Confusion about pandas copy of slice of dataframe warning
- Create a Pandas Dataframe by appending one row at a time
- Convert Pandas column containing NaNs to dtype `int`
- How to get a value from a cell of a dataframe?
- Is there a way in Pandas to use previous row value in dataframe.apply when previous value is also calculated in the apply?
- How can I split a column of tuples in a Pandas dataframe?
- python – Using pandas structures with large csv(iterate and chunksize)
- Group duplicate column IDs in pandas dataframe
- How to convert column with list of values into rows in Pandas DataFrame
- Remove or replace spaces in column names
- Return multiple columns from pandas apply()
- Filling in date gaps in MultiIndex Pandas Dataframe
- start index at 1 for Pandas DataFrame
- Multi Index Sorting in Pandas