How Do I add rows to Pandas dataframe to only the first 100 indices, while the other part is left unchanged?

23 Views Asked by At

I want to add more rows to only the first 105 indices of a dataframe (with zero elements in the columns), while the rest part of the row is left unchanged with a frequency of 2mins.

An example of dataframe df is seen below.

Time Z(dB) 0 1900-01-01 10:02:00 0.000 1 1900-01-01 10:04:00 0.000 2 1900-01-01 10:06:00 0.000 3 1900-01-01 10:08:00 0.000 4 1900-01-01 10:10:00 0.000 5 1900-01-01 10:12:00 0.000 6 1900-01-01 10:14:00 0.000 7 1900-01-01 10:16:00 0.000 8 1900-01-01 10:18:00 0.000 9 1900-01-01 10:20:00 0.000 10 1900-01-01 10:22:00 0.000 11 1900-01-01 10:24:00 0.000 12 1900-01-01 10:26:00 0.000 13 1900-01-01 10:28:00 0.000 14 1900-01-01 10:30:00 0.000 15 1900-01-01 10:32:00 0.000 16 1900-01-01 10:34:00 0.000 17 1900-01-01 10:36:00 0.000 18 1900-01-01 10:38:00 0.000 19 1900-01-01 10:40:00 0.000 20 1900-01-01 10:42:00 0.000 21 1900-01-01 10:44:00 0.000 22 1900-01-01 10:46:00 0.000 23 1900-01-01 10:48:00 0.000 24 1900-01-01 10:50:00 0.000 25 1900-01-01 10:52:00 0.000 26 1900-01-01 10:54:00 0.000 27 1900-01-01 10:56:00 0.000 28 1900-01-01 10:58:00 0.000 29 1900-01-01 11:00:00 0.000 33 1900-01-01 11:02:00 0.000 34 1900-01-01 11:04:00 0.000 35 1900-01-01 11:06:00 0.000 36 1900-01-01 11:08:00 0.000 37 1900-01-01 11:10:00 0.000 38 1900-01-01 11:12:00 0.000 39 1900-01-01 11:14:00 0.000

I have used script below but it only add new rows but doesn't go beyond the 105th indices. Beyond 105th row, I want the remain dataframe to remain unchanged.

df = df.set_index("Time")

idx = pd.date_range("1900-01-01 10:02:00", "1900-01-01 12:32:00", freq="1min")
df = df.reindex(idx, fill_value=0)
0

There are 0 best solutions below