# Plot from Excel sheet, 2 Columns, 1 of those columns with 2 categories

I have the following Excel csv sheet:

It tells if an university is Public or Private, then how in debt they are in USD. Control is only 1 or 2, (1 = Public, 2 = Private).

I want to make an statistic analysis between these 2 columns, comparing how much more debt there is for private universities. This means plotting Histograms, box-plots, etc. (I know how to plot those)

I also know how to Import all this data.

What I am missing is how to manipulate this data, specially in column CONTROL. I don't know how to "match" or "group" the 2 values of group and assign them to its corresponding DEBT value.

Sample of 50 Universities in Dropbox Link

The code I'm using to Import data is:

Import["C:\\Users\\cariasg\\Downloads\\Sample.csv", {"Data", Range[1, 50], {1, 2}}]


This one imports using a direct file path and only rows from 1 to 50 and columns 1 to 2.

• Can you upload (a small sample of) the Excel file somewhere, as well as show the code you used? – J. M. will be back soon Mar 30 '17 at 2:34
• added those two in the Answer section – TheDudeBro Mar 30 '17 at 2:43
• Next time, please edit your question to include additional details instead of posting it as an answer. – J. M. will be back soon Mar 30 '17 at 2:54

Short answer: Use GroupBy.

Suppose you've imported the data into a 2-column matrix data. An example:

data = { {1, 3388}, {2, 5679}, {2, 4567}, {2,8764}, {1, "PrivacySuppressed"} }


First you can filter out "PrivacySuppressed" entries with something like

dataFiltered = DeleteCases[ data, {_, "PrivacySuppressed"} ]


Then you can split the data according to the first entry using GroupBy :

GroupBy[ dataFiltered, First ]
(* <| 1 -> {{1, 3388}}, 2 -> {{2, 5679}, {2, 4567}, {2, 8764}} |> *)


Or better yet, you can remove the first column with

dataSplit = GroupBy[ dataFiltered, First -> Last ]
(* <| 1 -> {3388}, 2 -> {5679, 4567, 8764} |> *)


Then you can access the list of entries using

dataSplit[1]
(* {3388} *)
dataSplit[2]
(* {5679, 4567, 8764} *)