Skip to content
Snippets Groups Projects
Commit a4a322a4 authored by Nicolas Barthes's avatar Nicolas Barthes
Browse files

autodetect column index True or False when importing CSV data

parent 3232d795
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ import pandas as pd
import plotly.express as px
from sklearn.cluster import KMeans as km
from sklearn.metrics import pairwise_distances_argmin_min
from application_functions import pca_maker, model, predict, find_delimiter, umap_maker
from application_functions import pca_maker, model, predict, find_delimiter, umap_maker, find_col_index
# load images for web interface
img_sselect = Image.open("images\sselect.JPG")
......@@ -43,12 +43,11 @@ with st.container():
# Select list for CSV delimiter
psep = settings_column.selectbox("Select csv separator - _detected_: " + str(find_delimiter('data/'+sselectx_csv.name)), options=[";", ","], index=[";", ","].index(str(find_delimiter('data/'+sselectx_csv.name))), key=9)
# Select list for CSV header True / False
phdr = settings_column.selectbox("indexes column in csv?", options=["no", "yes"], key=31)
phdr = settings_column.selectbox("indexes column in csv? - _detected_: " + str(find_col_index('data/'+sselectx_csv.name)), options=["no", "yes"], index=["no", "yes"].index(str(find_col_index('data/'+sselectx_csv.name))), key=31)
if phdr == 'yes':
col = 0
else:
col = False
data_import = pd.read_csv(sselectx_csv, sep=psep, index_col=col)
# Select type of plot
plot_type=['', 'pca','umap']
......
......@@ -19,7 +19,11 @@ def find_delimiter(filename):
with open(filename) as fp:
delimiter = sniffer.sniff(fp.read(5000)).delimiter
return delimiter
def find_col_index(filename):
with open(filename) as fp:
lines = pd.read_csv(fp, skiprows=3, nrows=3, index_col=False, sep=str(find_delimiter(filename)))
col_index = 'yes' if lines.iloc[:,0].dtypes != np.float64 else 'no'
return col_index
# detection of columns categories and scaling
def col_cat(data_import):
# detect numerical and categorical columns in the csv
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment