I have a timeserie dataframe filled with 0 and a various number of columns and I would like to fill values in diagonal with 100 starting by the first row and the first column. I could use the solution proposed in the question bellow but it stops after value of the last column has been filled. Set values on the diagonal of pandas.DataFrame
How could I make it repeat over all rows?
This is how my dataframe looks like:
A B
2020-05-02 23:00:00+00:00 0.0 0.0
2020-05-03 00:00:00+00:00 0.0 0.0
2020-05-03 01:00:00+00:00 0.0 0.0
2020-05-03 02:00:00+00:00 0.0 0.0
2020-05-03 03:00:00+00:00 0.0 0.0
But as you can see using Numpy fill_diagonal doesn't complete the job.
import numpy as np
np.fill_diagonal(df.values, 0)
A B
2020-05-02 23:00:00+00:00 100.0 0.0
2020-05-03 00:00:00+00:00 0.0 100.0
2020-05-03 01:00:00+00:00 0.0 0.0
2020-05-03 02:00:00+00:00 0.0 0.0
2020-05-03 03:00:00+00:00 0.0 0.0
When there are 2 columns I would like is something like this:
A B
2020-05-02 23:00:00+00:00 100.0 0.0
2020-05-03 00:00:00+00:00 0.0 100.0
2020-05-03 01:00:00+00:00 100.0 0.0
2020-05-03 02:00:00+00:00 0.0 100.0
2020-05-03 03:00:00+00:00 100.0 0.0