Programmatically Combine Excel Worksheets on Certain Columns - Five Minute Python Scripts

Опубликовано: 15 Февраль 2025
на канале: Derrick Sherrill
33,908
1.1k

Hey Everyone! Subscriber request on how to programmatically join excel files in a directory using Pandas.

Support the Channel on Patreon --
  / derricksherrill  
Join The Socials --
Reddit -   / codewithderrick  
FB -   / codewithderrick  
Insta -   / codewithderrick  
Twitter -   / codewithderrick  
LinkedIn -   / derricksherrill  
GitHub - https://github.com/Derrick-Sherrill
*****************************************************************
Full code from the video:
import os
import pandas as pd

data_location = "ExcelData/"
desired_headings = ["Valuable Information"]
df_total = pd.DataFrame(columns=desired_headings)

for file in os.listdir(data_location):
df_file = pd.read_excel(data_location + file)
selected_columns = df_file.loc[:, desired_headings]
df_total = pd.concat([selected_columns, df_total], ignore_index=True)

df_total.to_excel("ValuableInformation.xlsx")

https://github.com/Derrick-Sherrill/D...

Packages (& Versions) used in this video:
Python 3.7
Pandas 0.25

*****************************************************************
Code from this tutorial and all my others can be found on my GitHub:
https://github.com/Derrick-Sherrill/D...

Check out my website:
https://www.derricksherrill.com/

If you liked the video - please hit the like button. It means more than you know. Thanks for watching and thank you for all your support!!

--- Channel FAQ --

What text editor do you use?
Atom - https://atom.io/

What Equipment do you use to film videos?
Blue Yeti Microphone - https://amzn.to/2PcNj5d
Mic sound shield - https://amzn.to/3bVNkEt
Soundfoam - https://amzn.to/37NV9ci
Camera desk stand - https://amzn.to/3bX8xhm
Box Lights - https://amzn.to/2PanL95
Side Lights - https://amzn.to/37KSNut
Green Screen - https://amzn.to/37SFFnc

What computer do you use/desk setup?
Film on imac (4k screen) - https://amzn.to/37SEu7g
Work on Macbook Pro - https://amzn.to/2HJ5b3G
Video Storage - https://amzn.to/2Pey8sw
Mouse - https://amzn.to/2PhCtv3
Desk - https://amzn.to/37O1Mv1
Chair - https://amzn.to/2uqHE4E

What editing software do you use?
Adobe CC - https://www.adobe.com/creativecloud.html
Premiere Pro for video editing
Photoshop for images
After Effects for animations

Do I have any courses available?
Yes & always working on more!
https://www.udemy.com/user/derrick-sh...

Where do I get my music?
I get all my music from the copyright free Youtube audio library
https://www.youtube.com/audiolibrary/...

Let me know if there's anything else you want answered!

-------------------------

Always looking for suggestions on what video to make next -- leave me a comment with your project! Happy Coding!