forked from vrlnarayana/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreaddata.py
More file actions
38 lines (35 loc) · 1.5 KB
/
readdata.py
File metadata and controls
38 lines (35 loc) · 1.5 KB
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
30
31
32
33
34
35
36
37
38
import streamlit as st
import pandas as pd
import appconfig #import for data file
import urllib
import pickle
import joblib
# @st.cache #cache data from dataframe to avoid loading it each time when the function is called
def read_user():
filename='userdf.csv'
user=pd.read_csv(filename,sep=',',index_col='sno')
return user
# read data and picke from gdrive
@st.cache(max_entries=10, ttl=3600)
def read_data_gdrive(file, type='data'):
file_type = file.split('.')[-1]
if file_type == 'pkl' and type == 'data':
pickle_url = appconfig.datapath(file)
pickle_path = 'https://drive.google.com/uc?export=download&id=' + pickle_url.split('/')[-2]
pickle_data = pickle.load(urllib.request.urlopen(pickle_path))
return pickle_data
elif file_type == 'pkl' and type == 'joblib':
joblib_url = appconfig.datapath(file)
joblib_path = 'https://drive.google.com/uc?export=download&id=' + joblib_url.split('/')[-2]
joblib_data = joblib.load(urllib.request.urlopen(joblib_path))
return joblib_data
elif file_type == 'csv':
csv_url = appconfig.datapath(file)
csv_path = 'https://drive.google.com/uc?export=download&id=' + csv_url.split('/')[-2]
csv_data = pd.read_csv(csv_path)
return csv_data
elif file_type == 'tsv':
tsv_url = appconfig.datapath(file)
tsv_path = 'https://drive.google.com/uc?export=download&id=' + tsv_url.split('/')[-2]
tsv_data = pd.read_csv(tsv_path, sep='\t')
return tsv_data