Created
February 23, 2024 12:46
-
-
Save salvadorgascon/fa20d282c4a55ea2341f9f4762d98b8f to your computer and use it in GitHub Desktop.
Python transformer to convert a bytes array containing EXCEL data into a Panda Object
This file contains 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
import datetime | |
import os | |
from pandas import read_excel | |
def ExcelDataframeTransformer(excel_binary, tmp_path): | |
print("Reading EXCEL") | |
filename = datetime.datetime.now().strftime("%Y%m%d%H%M%S") | |
print("Saving EXCEL into", tmp_path+'/'+filename+'.xls') | |
with open(tmp_path+'/'+filename+'.xls', 'wb') as f: | |
f.write(excel_binary) | |
print("Parsing EXCEL", tmp_path+'/'+filename+'.xls') | |
panda_object = read_excel(tmp_path+'/'+filename+'.xls') | |
print("Removing EXCEL", tmp_path+'/'+filename+'.xls') | |
os.remove(tmp_path+'/'+filename+'.xls') | |
return panda_object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment