I want to remove random() and enter date data

This is the original code.

import pandas as pd
import numpy as np
import warnings
import matplotlib.pyplot as plt

warnings.simplefilter('ignore')

# Common code for display result
def show_graph(df1,df2,title):
    data = pd.concat([df1, df2])
    data.reset_index(inplace=True, drop=True)
    for col in data.columns:
        if col.lower().startswith('pred'):
            data[col].plot(label=col,linestyle="dotted")
        else:
            data[col].plot(label=col)
    plt.title(title)
    plt.legend()
    plt.show()


from statsmodels.tsa.ar_model import AutoReg
from random import random

def AR_model(train,test):
    # fit model
    model = AutoReg(train['Act'], lags=1)
    model_fit = model.fit()
    # make prediction
    yhat=model_fit.predict(len(train), len(train) + len(test) - 1)
    res=pd.DataFrame({"Pred":yhat, "Act":test["Act"].values})
    return res
 
df_train = pd.DataFrame([x + random()*10 for x in range(1, 100)], columns=['Act']) <========
df_test = pd.DataFrame([x + random()*10 for x in range(101, 200)], columns=['Act']) <=========
df_ret = AR_model(df_train, df_test)

show_graph(df_train, df_ret, "Autoregression (AR)")

================
In the code above,
df_train = pd.DataFrame([x + random()*10 for x in range(1, 100)], columns=[‘Act’])
df_test = pd.DataFrame([x + random()*10 for x in range(101, 200)], columns=[‘Act’])

===> I want to remove random() from A code and input it as

Date Value
2022-07-24, -1.875071
2022-07-25, -3.015379
2022-07-26, -4.944132
2022-07-27, 12.053447
2022-07-28, -1.097842

How should I write the code?

Please re-enter your code.

First, press the following button: </>, then paste the code where it tells you to enter the code.

I did as you said.
Please help me

Correction. Ok, you have.

To be honest, I am not familiar with the pandas module package. Someone else on here that is familiar with it can help you with that.

However, for the dates that you state, you can potentially define them as a dictionary since it appears that they are provided in date and value pair (or key / value pair) as:

dates = {'2022-07-24': -1.875071,
         '2022-07-25': -3.015379,
         '2022-07-26': -4.944132,
         '2022-07-27': 12.053447,
         '2022-07-28': -1.097842}

The following two imports should be included at the top of the module along with the other imports.

from statsmodels.tsa.ar_model import AutoReg
from random import random

Just a general recommendation, try to space out your code for better readability.

If you want to loop and obtain ONLY the value, you can iterate as:

for key in dates.values():
    print(key)

Similarly, you potentially can incorporate that into your code as:

df_train = pd.DataFrame((for key in dates.values()), columns = ['Act'])

If you wish to incorporate both key and value, you can obtain them as:

for key, value in dates.items():
    print(f"{key}: {value}")

If you wish to incorporate them into that panda line of code:

df_train = pd.DataFrame((for key, value in dates.items()), columns = ['Act'])

Small suggestion:

Comment out the following character made arrows otherwise they will cause an error:

# <========

Do you know how to prompt the user to input some text?
Do you understand how to convert text that represents a date, into the corresponding date object, according to some format?
If you put these pieces together, does it not solve the problem?