-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_contents.py
More file actions
29 lines (21 loc) · 806 Bytes
/
parse_contents.py
File metadata and controls
29 lines (21 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import base64
import io
import dash_html_components as html
import pandas as pd
def parse_contents(contents, filename, date):
content_type, content_string = contents.split(',')
decoded = base64.b64decode(content_string)
try:
if 'csv' in filename:
# Assume that the user uploaded a CSV file
df = pd.read_csv(
io.StringIO(decoded.decode('utf-8'))).dropna(how='all')
elif 'xls' in filename:
# Assume that the user uploaded an excel file
df = pd.read_excel(io.BytesIO(decoded)).dropna(how='all')
except Exception as e:
print(e)
return html.Div([
'There was an error processing this file.'
])
return df.dropna(how='all').to_json(date_format='iso', orient='split')