'Pandas append() will be deprecated and I can't convert a specific df.append() to df.concat()

I have a current iteration to fill new rows to a dataframe based on new series created:

for i in range (x):
    nextMonth = df.index[-1] + DateOffset(months=1)
    newRow = pd.Series({'col_1':None,'col_2':1}, name=nextMonth)
    df = df.append(newRow)

This works fine. New rows are created, on correct df columns (col_1 and col_2) and I have a correct nextMonth named index on the df (2022-02-01 on date).

              col_1  col_2
date
1994-07-01  0.0684   7.177511
1994-08-01  0.0186   6.718000
1994-09-01  0.0153   6.595327
1994-10-01  0.0262   6.495939
1994-11-01  0.0281   6.330091
...            ...        ...
2021-10-01  0.0125   1.035140
2021-11-01  0.0095   1.022360
2021-12-01  0.0073   1.012739
2022-01-01  0.0054   1.005400
2022-02-01     NaN   1.000000 -----> series added

Note that I'm using the series named indexes to match with the df columns, and I´m also using the series name to use it on the final df as a named index (nextMonth).

Since df.append() will be deprecated, I´m struggling to perform the same instructions using df.concat().



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source