0

When saving DF to excel workbook, how can I pick specific cells for data to go into?

EX:

1 390.0
2 1390.0
3 94.0
4 50.0
5 1.0
6 70.0

1 would be in "A1"
2 would be in "A4"

etc

df.to_excel("output.xlsx") is there anything else I can add to this? or another way to do it?

thank you

Алексей Р
  • 7,507
  • 2
  • 7
  • 18

1 Answers1

0

The task is not quite clear, but if it is to arrange the output lines with a certain gap, this can be done like this:

df = pd.DataFrame({'A': [1, 2, 3, 4, 5, 6], 'B': [390.0, 1390, 94, 50, 1, 70]})
gap = 2
df = df.groupby(level=0).apply(lambda x: pd.concat([x, pd.DataFrame([None]*gap)], ignore_index=True))
df.to_excel("output.xlsx", header=False, index=False, startrow=0, startcol=0)

Output:
enter image description here

Алексей Р
  • 7,507
  • 2
  • 7
  • 18
  • Appreciate your input and apologize my question was vague. Forgive my lack of proper verbiage as I am merely an amateur at python, but: I have a dataframe that I did a groupby on. It left me with two columns. the first column is equal job location # 1. Second column is equal to amount of material being used. I wish to export this to an already made spreadsheet that has predefined spaces for job location and material required but are however empty. Any help would be appreciated. – joeinreallife Aug 27 '22 at 21:45
  • @joeinreallife see the [solution with openpyxl](https://stackoverflow.com/a/34559425/15035314) – Алексей Р Aug 28 '22 at 02:48