0

This is my code:

df = pd.read_csv(r'C:\Neuer Ordner\Strompreis.csv',
             sep=';',
            encoding = 'unicode_escape',
            index_col=0,
            parse_dates=True
            )
dd = list()
for i in range (0,5):

        x = df.values[len(df)-5]
        y = df.values[len(df)-3]
        z = 0.5*x + 0.7*y
        dd.append(z)
        dx = pd.DataFrame(dd)
        df = pd.concat([df, dx])

This is the head of the input dataframe

                     Strompreis
Daten   
2019-11-25 22:45:00     34.97
2019-11-25 23:00:00     48.61
2019-11-25 23:15:00     36.66
2019-11-25 23:30:00     36.74
2019-11-25 23:45:00     33.83

The expected Outputs must include the new values of z, like

Strompreis
Daten   
2019-11-25 22:45:00     34.97
2019-11-25 23:00:00     48.61
2019-11-25 23:15:00     36.66
2019-11-25 23:30:00     36.74
2019-11-25 23:45:00     33.83
2019-11-25 00:00:00     41.5
2020-01-01 00:15:00     36.9
2020-01-01 00:30:00     45.9
...

the value of z2 must be calculated based on the new dataframe (including z1)

  • 2
    Please show a hard coded example of an input dataframe and what your expected outputs from this dataframe should look like. – Scott Boston Dec 12 '19 at 14:32
  • @ScottBoston thanks for replying. the input and the expected dataframe can be found below – Ahmed Madiouni Dec 12 '19 at 14:45
  • 1
    it is better if you edited your question and added the input and expected output dataframes the question. – Scott Boston Dec 12 '19 at 14:47
  • 1
    On line 6 of your expected outputs, where did the value of the index come from and how did you calculate 41.5? – Scott Boston Dec 12 '19 at 15:30
  • t = pd.date_range(start=(df.index[len(df)-1]) , periods=n, freq='15min') new_df = pd.DataFrame([[x, y] for x,y in zip(t, z)], columns=["Daten", "Strompreis"]) df = pd.concat([df,new_df]) #41.5 is the value of z for (i=1) – Ahmed Madiouni Dec 12 '19 at 16:21

0 Answers0