Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to append rows with concat to a Pandas DataFrame

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()

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

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading