Julia group name and amount calculation

I'm new to Julia and have a simple question. I have a csv file with the following structures: [Category, Name, Account]. I have 2 things that I want to create.

1, i want to create a function in julia that groupBy categories and add counters (name is ignored). So the output will be [Name, Count]. Then I will create a chart bar by setting x = Name and y = Count

2, I want to create multiple plots for each category, with each name plotted on separate line plots. So, an iterative charting process?

I think I have a plot, but I'm not sure how to make the groupBy process. Any help / re-guidance to the tutorials would be greatly appreciated.

Sample of my data:

(net_worth,khan,14)
(net_worth,kevin,15)
(net_worth,bill,16)

      

the function I'm currently working on:

function wordcount(text,opinion,number)
words= text
counts= Dict()
  for w = words
    counts[w]= number
  end
return counts
end

function wcreduce(wcs)
counts=Dict()
  for c in wcs, (k,v) in c
    counts[k] = get(counts,k,0)+v
  end
return counts
end

      

I'm looking for a function like reduceByKey or GroupByKey I think.

+3


source to share


1 answer


So I solved it using Julia's DataFrames feature,

First load the csv data using:

data = readtable("iris.csv")

      



Now its function:

function trendingkeys(data::DataFrame,trends::Symbol,funcadd::Function)
  by(data, :trends, funcadd -> sum(funcadd[:counts]))
end

      

I have to say. DataFrame is so smart.

+4


source







All Articles