Created
June 8, 2023 17:56
-
-
Save firobeid/2efa132c47e524c71fcddf2fcacb81a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| path = '%s/%s'% (path_dir, file_name) | |
| if file_name not in os.listdir(path_dir): | |
| writer = pd.ExcelWriter(path=path, engine= "openpyxl") | |
| fp = open(path, 'w', encoding='utf-8') | |
| else: | |
| writer = pd.ExcelWriter(path=path, engine= "openpyxl", mode = 'a', if_sheet_exists = 'replace') | |
| def save_sheet(df, metric_name, exits = True): | |
| try: | |
| temp_df = df.reset_index().rename(columns = {'index':period_metrics.value}).T.reset_index().T | |
| except: | |
| temp_df = df.reset_index().rename(columns = {'index':'MONTH'}).T.reset_index().T | |
| pass | |
| if exits: | |
| existing_output = pd.read_excel(path, | |
| sheet_name=metric_name, | |
| parse_dates = True, engine = 'openpyxl') | |
| temp_df.to_excel(writer, sheet_name=metric_name, | |
| header=False,index = False, | |
| startcol = existing_output.shape[1] + 1 | |
| ) | |
| else: | |
| temp_df.to_excel(writer, sheet_name=metric_name, | |
| header=False,index = False) | |
| writer.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment