Message Boards Message Boards

1
|
5795 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Remove elements with a specific value?

Posted 4 years ago
Attachments:
POSTED BY: Tester Trying
5 Replies
Posted 4 years ago

Change Drop[suicide2[All], "2016"] to Select[suicide2, #[[2]] != 2016 &] or DeleteCases[suicide2, {x_, 2016., y___}] like Hans suggested. Both will do the same thing from a different perspective.

POSTED BY: Sean Cheren

I had to change the the fileformat (converted it to .xls). Then

OriginalData = Import["C:\Users\User\Desktop\suicide.xls"];

and

test = Take[OriginalData[[1]], 50];
test // TableForm
test1 = DeleteCases[test, {x_, 1988., y___}];
test1 // TableForm

Is it this what you are looking for?

POSTED BY: Hans Dolhaine
Posted 4 years ago
POSTED BY: Tester Trying
Posted 4 years ago

I recommend using {"Data", 1} to select the first sheet as it is more efficient than taking the first part after importing everything. Then, you want to select each row where the second position is not 2016 (its a number, not a string).

In[6]:= data = Import["~/Downloads/suicide.xlsx", {"Data", 1}];

In[12]:= data // Length
Out[12]= 27821

In[13]:= Select[data, #[[2]] != 2016 &] // Length
Out[13]= 27661
POSTED BY: Sean Cheren
Posted 4 years ago

Hey Sean,

thank you very much for that hint! I want all rows to be deleted where the value year (second column) is 2016.

Thanks a lot :)

POSTED BY: Tester Trying
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