0
df1=pd.read_csv('out.csv')
df2=pd.read_excel('somefile.xls')

#put columns from df1 to df2

df2['eer']=df1['eer']
df2['wer']=df1['wer']
df2['zer']=df1['zer']
df2['qer']=df1['qer']
df2['der']=df1['der']

#make a new file with somefile.xls columns + the ones above

newfile = input("Enter a name for the combined file: ")
writer = pd.ExcelWriter(newfile)
df2.to_excel(writer)
writer.save()

I have this part of the code at the end of my program using python pandas module, so whenever I generate the new file with all the columns i need, column A has some kind of index going from 0 to the end row, instead of 'Name' which is what somefile's column A is. 'Name' is now column B.

like this

0
1
2
3
4
5
6
7
8
9
DaVinci
  • 97
  • 1
  • 1
  • 9

1 Answers1

1

This question is a dupe of many many others, but all you would do is change

df2.to_excel(writer)

to

df2.to_excel(writer, index=False)
  • You are right, this has been asked before. I've voted to close the question as a duplicate. For the future, since you have enough reputation to comment, I suggest that you leave a comment on the main question which links to the question you think it's a duplicate of. That will make it easier for other users to notice and vote. Of course, at some point, you may have enough rep to vote yourself. If you hadn't had enough rep to comment, I would have suggested instead to include the link in your answer. – John Y Aug 05 '16 at 14:46
  • Sorry, I didn't have comment privileges when I posted this. I just blanked on putting a link in. Should I edit that in? – Henry Prickett-Morgan Aug 07 '16 at 19:15
  • For this particular case, I don't think there's any need to edit your answer now. The question has already been closed as a duplicate, and it's also a very simple question and very simple answer. That being said, any time you feel you can *improve* one of your posts by editing it, you are certainly encouraged to do so. – John Y Aug 07 '16 at 22:36
  • Thanks for the advice. I am pretty new here :) – Henry Prickett-Morgan Aug 08 '16 at 15:22