0

As the new version of pandas, pandas 2.0, removed the df.append method, how to modify the following code to add a dictionary to a pandas dataframe.

The old version of code is:

record_score = {}
record_score["model_name"] = model_name
record_score["time"] = crt_time
record_score["epoch"] = best_epoch
record_score["best_score"] = best_score

# save best to file
record_path = "./record.csv"
if not os.path.exists(record_path):
    record_table = pd.DataFrame()
else:
    record_table = pd.read_csv(record_path)
record_table = record_table.append(record_score, ignore_index=True)
record_table.to_csv(record_path, index=False)

I think now i can just create a new dataframe from the record_score and use pandas.concat to concat the data.

I hope someone can give me some advice to modify the code with an efficient way. Thanks a lot.

  • Does this answer your question? [Good alternative to Pandas .append() method, now that it is being deprecated?](https://stackoverflow.com/questions/70837397/good-alternative-to-pandas-append-method-now-that-it-is-being-deprecated) – Marcelo Paco Apr 15 '23 at 03:21

0 Answers0