r/programmingrequests • u/jon_snow82 • Jun 26 '19
Adding filename to each row in excel file
Howdy. I am using the code from here to combine multiple csv files. My knowledge of vba is mostly copy pasting and google-fu.
What I am requesting for is a piece of code that will add the file name to each row of the column after the last column of each csv file before it is combined so that I can identify which file the data has come from.
OR
A program from scratch which will copy/paste the name of the csv file to the last column of each row of the particular csv file and then combine them (copy paste them on top of each other (the csv filenames are years 2015, 206, 2017 and so on, so they will hopefully be pasted in order (but it is not necessary)).
Appreciate any help. Thank you.
View all comments
Show parent comment
1
u/POGtastic Jun 26 '19
Doing some more research, I'd use
glob.Call with the same wildcard syntax - the difference is that it's the Python program expanding the wildcard to the filenames, not the shell.
If you already know how to program, the official tutorial is very good. Unfortunately, I have a lot less guidance on how to learn programming through Python, as I came from a C++ / Perl / Common Lisp background and just translated most of the concepts I already knew to their Python equivalents. There are a variety of textbooks, and my general attitude is "Anything works as long as it forces you to do a ton of examples." I'm good at programming because I've sunk thousands of hours into doing large and small problems, not because of any particular resources that I've used.