Skip to content

Instantly share code, notes, and snippets.

@Dhrumilcse
Last active May 20, 2021 04:41
Show Gist options
  • Save Dhrumilcse/1684c0dbace7b93db1044bb8680d2ec3 to your computer and use it in GitHub Desktop.
Save Dhrumilcse/1684c0dbace7b93db1044bb8680d2ec3 to your computer and use it in GitHub Desktop.
#Event handler for upload button
def upload_btn_eventhandler(obj):
#Clear output before each run
with data_process_output:
clear_output()
#Read file
for file_name in upload_file.value:
#Split file name to extract data
extension = file_name.split('.')[1]
content = upload_file.value[file_name]['content']
if(extension == 'xlsx' or extension == 'xls'):
data = pd.read_excel(BytesIO(content))
elif(extension == 'csv'):
data = pd.read_csv(BytesIO(content))
else:
print("File not accepted")
# Calling another function to filter data (next step)
# filter_data(data)
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment