How to append rows with concat to a Pandas DataFrame

Dew*_*ops 5 python dataframe pandas

I have defined an empty data frame with:

insert_row = {
    "Date": dtStr,
    "Index": IndexVal,
    "Change": IndexChnge,
}
data = {
    "Date": [],
    "Index": [],
    "Change": [],
}
df = pd.DataFrame(data)
df = df.append(insert_row, ignore_index=True)

df.to_csv(r"C:\Result.csv", index=False)
driver.close()
Run Code Online (Sandbox Code Playgroud)

But I get the below deprecation warning not to use df.append every time I run the code

在此输入图像描述

Can anyone suggest how to get rid of this warning by using pandas.concat?

Cor*_*ien 11

Create a dataframe then concat:

insert_row = {
    "Date": '2022-03-20',
    "Index": 1,
    "Change": -2,
}

df = pd.concat([df, pd.DataFrame([insert_row])])
print(df)

# Output
         Date  Index  Change
0  2022-03-20    1.0    -2.0
Run Code Online (Sandbox Code Playgroud)