From b264f4a39b44d8dd30372e339249dd1171194c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Sand=20Jensen?= <bjje@dtu.dk> Date: Fri, 26 Jan 2024 19:48:07 +0100 Subject: [PATCH] Print the data file location in ex1.5.1-1.5.3,1.5.5 --- exercises/02450Toolbox_Python/Scripts/ex1_5_1.py | 6 ++++++ exercises/02450Toolbox_Python/Scripts/ex1_5_2.py | 10 +++++++--- exercises/02450Toolbox_Python/Scripts/ex1_5_3.py | 10 ++++++++-- exercises/02450Toolbox_Python/Scripts/ex1_5_5.py | 8 +++++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/exercises/02450Toolbox_Python/Scripts/ex1_5_1.py b/exercises/02450Toolbox_Python/Scripts/ex1_5_1.py index d5c7463..41c5373 100644 --- a/exercises/02450Toolbox_Python/Scripts/ex1_5_1.py +++ b/exercises/02450Toolbox_Python/Scripts/ex1_5_1.py @@ -5,6 +5,12 @@ import pandas as pd # Load the Iris csv data using the Pandas library filename = importlib_resources.files("dtuimldmtools").joinpath("data/iris.csv") + +# Print the location of the iris.csv file on your computer. +# You should inspect it manually to understand the format and content +print("\nLocation of the iris.csv file: {}".format(filename)) + +# Load the iris.csv file using pandas df = pd.read_csv(filename) # Pandas returns a dataframe, (df) which could be used for handling the data. diff --git a/exercises/02450Toolbox_Python/Scripts/ex1_5_2.py b/exercises/02450Toolbox_Python/Scripts/ex1_5_2.py index 7c28d1b..d421597 100644 --- a/exercises/02450Toolbox_Python/Scripts/ex1_5_2.py +++ b/exercises/02450Toolbox_Python/Scripts/ex1_5_2.py @@ -11,11 +11,15 @@ import xlrd # data to excel files, see the following tutorial: # http://www.simplistix.co.uk/presentations/python-excel.pdf} -# Load xls sheet with data -# There's only a single sheet in the .xls, so we take out that sheet - +# Get path to the datafile filename = importlib_resources.files("dtuimldmtools").joinpath("data/iris.xls") +# Print the location of the iris.xls file on your computer. +# You should inspect it manually to understand the format and content +print("\nLocation of the iris.xls file: {}".format(filename)) + +# Load xls sheet with data +# There's only a single sheet in the .xls, so we take out that sheet doc = xlrd.open_workbook(filename).sheet_by_index(0) # Extract attribute names diff --git a/exercises/02450Toolbox_Python/Scripts/ex1_5_3.py b/exercises/02450Toolbox_Python/Scripts/ex1_5_3.py index 97b9692..cf1fbac 100644 --- a/exercises/02450Toolbox_Python/Scripts/ex1_5_3.py +++ b/exercises/02450Toolbox_Python/Scripts/ex1_5_3.py @@ -7,10 +7,16 @@ from scipy.io import loadmat # The matlab workspace is loaded as a dictionary, with keys corresponding to # matlab variable names, and values to arrays representing matlab matrices. -# Load Matlab data file to python dict structure - +# Get path to the datafile filename = importlib_resources.files("dtuimldmtools").joinpath("data/iris.mat") + +# Print the location of the iris.mat file on your computer. +# You should inspect it manually to understand the format and content +print("\nLocation of the iris.mat file: {}".format(filename)) + +# Load Matlab data file to python dict structure iris_mat = loadmat(filename, squeeze_me=True) + # The argument squeeze_me ensures that there the variables we get from the # MATLAB filed are not stored within "unneeded" array dimensions. diff --git a/exercises/02450Toolbox_Python/Scripts/ex1_5_5.py b/exercises/02450Toolbox_Python/Scripts/ex1_5_5.py index e1b6d01..4b761a8 100644 --- a/exercises/02450Toolbox_Python/Scripts/ex1_5_5.py +++ b/exercises/02450Toolbox_Python/Scripts/ex1_5_5.py @@ -9,7 +9,13 @@ import pandas as pd # We start by defining the path to the file that we're we need to load. # Upon inspection, we saw that the messy_data.data was infact a file in the # format of a CSV-file with a ".data" extention instead. -filename = importlib_resources.files("dtuimldmtools").joinpath("data/messy_data/messy_data.data") +foldername = importlib_resources.files("dtuimldmtools").joinpath("data/messy_data") +filename = foldername.joinpath("messy_data.data") + +# Print the location of the messy_data folder and file. +# You should inspect it manually to understand the format and content +print("\nLocation of the messy_data folder: {}".format(foldername)) +print("\nLocation of the messy_data.data file: {}\n".format(filename)) # First of we simply read the file in using readtable, however, we need to # tell the function that the file is tab-seperated. We also need to specify -- GitLab