0

I have a DataFrame loaded from a CSV file which I would like to append with a new row of values and then save it back to CSV. However, there are a few characteristics to this DataFrame:

  • Its columns are not all of the same time, some are strings, some are floats (which makes this method not work for me;
  • Its index is a datetime format which only needs to register the date, so whenever using df.loc[datetime] = [value1, value2, .., value_n] (as mentioned here), if the index already exists in my DataFrame, all rows containing the same date will be updated with the inputs;

One solution I managed to come up with was to create a new 1-row DataFrame from a dict using the original's columns as keys, so I could then apply pd.concat to add the new row, but I am wondering if there is a simpler and more elegant way to do this?

manoelpqueiroz
  • 575
  • 1
  • 7
  • 17

1 Answers1

0

you can append 1 row, with or without the index:

df = df.append(pd.DataFrame({'value_1':value_1,'value_n':value_n},index=this_index))

df = df.append({'value_1':value_1,'value_n':value_n},ignore_index=True)