Remove elements with a specific value?

Hello everyone,

I have a dataset: Suicde Data from 1985 until 2016.

For the year 2016 there have been not so many sufficient records so I want to delete all entries from year 2016. Which means in the excel file I want to get rid of all rows where the first column has the value 2016.

OriginalData = 
  Import[FileNameJoin[{NotebookDirectory[], "suicide.xlsx"}]][[1]];

Export[FileNameJoin[{NotebookDirectory[], "suicide.mx"}], OriginalData]

suicide2 = 
 Import[FileNameJoin[{NotebookDirectory[], 
    "suicide.mx"}]];
suicide = Drop[suicide2[All], "2016"] (*With this command I intended to remove the lines from the data "suicide2", but it did not work.*)

Could you please let me know how to remove all entries from the year 2016? I have attached the xlsx file.

Thank you very much in advance!
[1]: Suicide Rates Overview 1985 to 2016 | Kaggle

suicide.xlsx (1.62 MB)

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

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?

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 :slight_smile:

Hey Hans,

thank you very much for your response. I tried your command but it did not work and I can not really recall what it should execute. I wish to delete all rows where the value is 2016 in column 2. :slight_smile:

Thank you very much!

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.