Pandas examples
Jump to navigation
Jump to search
Pandas Example of Reading Excel Spreadsheets
Example of reading existing excel
#!/usr/bin/env python3 import pandas as pd import ast from openpyxl import load_workbook def get_repo_lines_set(file_name): lines = [] lines_set = [] rt = [] dfs = {} dfs = pd.read_excel(file_name, sheet_name=None) for df_name in dfs.keys(): df = dfs[df_name] if 'git_repo_lines' in df.columns and 'delete' in df.columns: for idx, row in df.iterrows(): if row['delete'] == True: # print(row['delete']) lines.extend(ast.literal_eval((row['git_repo_lines']))) lines_set = list(set(lines)) for line in lines_set: parts = line.split(":") rt.append(f"{parts[0]}:{parts[1]}") return rt def main(): # global dfs global excel_file hosts = ['one', 'two'] lines_set = [] for i in hosts: excel_file = f"{i}.foo.xlsx" lines_set.extend(get_repo_lines_set(excel_file)) lines_set = list(set(lines_set)) lines_set.sort() for line in lines_set: print(line) if __name__ == "__main__": main()