How it works

Upload & Edit
Your PDF Document
Save, Download,
Print, and Share
Sign & Make
It Legally Binding
Video instructions and help with filling out and completing merge csv files with different headers
Instructions and Help about merge csv files with different headers

So in a loss script that we wrote from the previous section we added a new column to our csv files which contain the name of the station for each row in this lecture i'll write a script that we've come catenate all these files into a single csv file the reason I'll do this is that I want to create a summary statistics and private tables out of this data so it's good to have them in a single file so I'll go ahead and create a concatenation function now call it concatenate and we improve the directory where the files to be concatenated are located and I'll specify the output file path here and as usual let's set the current working directory to the input directory and generate a list of csv files using the glob method now the way we will be concatenating the data frames is by first stacking these data frames in to a simple Python list so we will store the data frames to always because remember we can store every kind of Python object in in a list including data frames and after we have finished storing all the data frames in the list we will pass the list to the concatenate panas method and the concatenate method will generate a single data frame out of all the list data frames so before starting the loop we need to create an empty list object so let's say DF list equals to empty square brackets and that creates an empty list for us then we want to iterate through the file list now let's print alt H file name as the loop goes forward so this is just to check how the script execution is going then we want to generate a data frame out of this fall we have no hydrogen our city Falls once I have generated a data frame I append this data frame to my empty list so the first iteration will add the first data frame to the anti list the second loop will append the second data frame to the list which already has one data frame and so on and here is where we end the loop so we just need a data frame list from the loop after that we don't need to iterate anymore so we don't indent here here is where we want to concatenate all these data frames so let's name the variable concat DF that is equal to pandas concat and in the concat method we will pass the data frame list and the axis because we want our data frame our data frames to be concatenated vertically we pass 0 in the axis now we are ready to export the united data frame to a new big csv file but before we do just that i would like to actually name the columns of the data frame if you go to the PI ftp side where we.