Julia stores a partitioned data frame in a dictionary

Trying to translate the python script into Julia and Julia seems more than before (admittedly, I have a very primitive understanding of Julia, so I expected some difficulty). In a nutshell, I'm trying to split a data frame into a column vector (which has 32 levels!), And then write these sectioned data frames into text. In python, I was kindly recommended to write something like this in order to split data frames and save them in a dict file:

injuries = {injury: df[df['Type'] == injury] for injury in df['Type'].unique()}

injuries['BROKEN PELVIS']

Does anyone know how to achieve something like this in Julia? I would suggest that Julia is syntactically similar, but all my efforts have so far been fruitless. Any input is truly appreciated. Thank you Chase CB

+3
source share
1 answer

Allows you to compile some data:

df = DataFrame(val=rand(8), injury = [rep("shoulder",4), rep("leg",4)])

This version does the same as the Python version:

injuries = [injury=>df[df[:injury] .== injury,:] for injury in unique(df[:injury])]

Now injuriesa DataFrames dictionary, one DataFrame for each injury. You can simply do:

injuries["shoulder"]

and it returns a DataFrame only with shoulder injuries.

+3
source

All Articles