Message Boards Message Boards

Automate converting an imported excel spreadsheet to a dataset?

Posted 5 years ago
POSTED BY: Mike Luntz
4 Replies
Posted 5 years ago

Not sure if this is exactly what you are after, but you can Import Excel directly as a Dataset.

dataset = Import["~/Downloads/Times_Square_Hotels.xlsx", "Dataset",  HeaderLines -> 1]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 5 years ago

Many thanks Rohit. I was not aware that you could import directly to a dataset. That solves my problem.

Is that capability documented anywhere? By the way, when I imported the file with your suggested command I got an error message stating

"Import::hdrs: The value 1 for the option "HeaderLines" is outside of the data range."

In spite of the error message the file apparently imported correctly.

POSTED BY: Mike Luntz

To get help have a look in Mathematica help of XLSX.

A follow up question: I imported Excel file as Rohit suggested and wanted to use it in Classify function. I can import Excel file as "Data" or "Dataset". Each row contains data for each patient, as Rohit has shown for a table of customers. I have two Excel sheets each for Condition1 and Condition2, both with same 26 columns structure for about 85 patients.

My problem is that Classify[ Condition1->1, Condition2->2] uses each table as if this was one patient, so as if I have two patients for training and not 85.

I tried to use Partition function to force reading each row as one patient bit without success. Partition[ Condition1, 26] or Partition[ Condition1, {26,1}] gives me an error of wrong dimension, which I cannot correct. Do I have to read Excel file row after row, our there is a more clever way?

POSTED BY: Marcin Balcerzyk
Posted 5 years ago

Marcin,

If condition1 is a Dataset then Normal[condition1] should be a list of 85 lists each of length 26. You want each of the 85 to be assigned the label 1. One way to do this is Thread[Normal[condition1] -> 1]]. Do the same for condition2 with label 2. Passing both results to Classify should work.

Rohit

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract