1
$\begingroup$

I have the following Excel csv sheet: enter image description here

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.

thanks in advance.


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.

$\endgroup$
3
  • $\begingroup$ Can you upload (a small sample of) the Excel file somewhere, as well as show the code you used? $\endgroup$ Mar 30, 2017 at 2:34
  • $\begingroup$ added those two in the Answer section $\endgroup$
    – TheDudeBro
    Mar 30, 2017 at 2:43
  • $\begingroup$ Next time, please edit your question to include additional details instead of posting it as an answer. $\endgroup$ Mar 30, 2017 at 2:54

1 Answer 1

2
$\begingroup$

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} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.