Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.3K Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Import only specfic columns and rows from XLSX file

Posted 1 year ago
POSTED BY: Ehud Behar
5 Replies
Posted 1 year ago

Thanks.

My question is about specyfying rows to be imported.

Can I import only row 2 (which will be used as a header) and rows 4 to 7?

Something like

Import["data.xlsx", {
  "Dataset",
  1,(*in sheet no. 1*)
  {2, 5 ;; 7},(*import row 2 and rows 4 to 7*)
  2 ;; 3}, (*import only 2nd and 3rd columns *)
 "SkipLines" -> 
  1, (*skip the message automatically generated by software*)
 HeaderLines -> 1 (*use current and voltage as headers*)
 ]

?

POSTED BY: Ehud Behar

A Span cannot be combined with an Integer. You can explicitly enumerate the rows

Import["data.xlsx",
 {"Dataset", 1, {1, 2, 4, 5, 6}, 2 ;; 3},
 "SkipLines" -> 1,
 HeaderLines -> 1 ]
POSTED BY: Rohit Namjoshi
Posted 1 year ago

That solves the confusion.

POSTED BY: Ehud Behar

You can convert a simple Span to a Range using Apply

Range @@ (4 ;; 7)
(* {4, 5, 6, 7}  *)

and use it to build the list. This might be useful if you have several disjoint Span

{1, 2, Sequence @@ Range @@ (4 ;; 7), Sequence @@ Range @@ (10 ;; 13)}
(* {1, 2, 4, 5, 6, 7, 10, 11, 12, 13} *)
POSTED BY: Rohit Namjoshi

I don't think skipping row 3 can be done during import. You did not provide the file so we make one

SeedRandom[123];
data = RandomReal[1, {10, 3}]

fileData = {{"File generated automatically by software", "", ""}, {"t", "current", "voltage"}}~Join~data
Export["data.xlsx", fileData]

dataset = 
  Import["data.xlsx", {"Dataset", 1, 1 ;; 7, 2 ;; 3}, 
    "SkipLines" -> 1,
     HeaderLines -> 1] // Rest
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