0

I have an existing excel file in documents which I open as a data frame with df = pd.read_excel(filename, index_col ='respID') and then I read and treat as a normal data frame.

I process some data and I then have two dictionaries whose key values are the same as the index values of the data frame.

I'm looking to insert these dictionaries into the excel file after a specific column. How would I go about doing this. Would it be better if they were just series?

I've seen solutions How to write to an existing excel file without overwriting data (using pandas)? and Pandas Series to Excel but I don't think either answers my question totally.

Worst comes to worst I can add the dictionaries to the data frame where I want them and just overwrite the entire excel file or write a new one and replace it but that seems inelegant.

Thank you.

Community
  • 1
  • 1
MilesConn
  • 301
  • 2
  • 13
  • You can make a dictionary a `pd.Series` with `pd.Series(mydict)` – piRSquared May 08 '17 at 23:53
  • Right and if I added that series to the data frame then would it automatically update the excel file? I don't think so because I believe the data frame has just read the excel file they're not interconnected although I could be wrong. – MilesConn May 09 '17 at 00:15
  • 1
    Correct, pandas maintains no connections to Excel. You need to export back into Excel format. – Parfait May 09 '17 at 02:56

0 Answers0