Skip to content

Instantly share code, notes, and snippets.

@elowy01
Last active September 14, 2021 16:12
Show Gist options
  • Save elowy01/2cb9ab0d4e629ef4d3c939e5f3c41496 to your computer and use it in GitHub Desktop.
Save elowy01/2cb9ab0d4e629ef4d3c939e5f3c41496 to your computer and use it in GitHub Desktop.
### Document on to deal with Excel (.xlsx) files in Python
# read-in Excel files into Pandas DF
import pandas as pd
DF = pd.read_excel('path/file.xlsx', 1) # 1 is the ix of the worksheet
# we want to parse
# concatenate different workbooks into a single workbook
# ex extracted from :
# https://towardsdatascience.com/merging-spreadsheets-with-python-append-f6de2d02e3f3
import pandas as pd
# Read all three files into pandas dataframes
marketing_analyst_names = pd.read_excel("MarketingAnalystNames.xlsx")
sales_rep_names = pd.read_excel("SalesRepNames.xlsx")
senior_leadership_names = pd.read_excel("SeniorLeadershipNames.xlsx")
# Create a list of the files in order you want them appended
all_df_list = [marketing_analyst_names, sales_rep_names, senior_leadership_names]
# Merge all the dataframes in all_df_list
# Pandas will automatically append based on similar column names
appended_df = pd.concat(all_df_list)
# Write the appended dataframe to an excel file
# Add index=False parameter to not include row numbers
appended_df.to_excel("AllCompanyNames.xlsx", index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment