I have df like this:
How can I get values from “<=50K” and “>50K” of “19-30”, “41-50”. And then i want to make a group bar from 2 values. Anyone can answer me this question. Thank you so much
I would recommend you to read through part of DataFrames’ manual: Working with DataFrames · DataFrames.jl
Also, it will be much easier for others to help you if you have run-able code that can produce toy dataframe, as well as the expect output.
My guess is this is what you’re looking for:
julia> df
10×3 DataFrame
Row │ income agerange count
│ Float64 Int64 Int64
─────┼────────────────────────────
1 │ 0.672059 1 44
2 │ 0.0819106 2 91
3 │ 0.148481 3 50
4 │ 0.540397 4 74
5 │ 0.209084 5 24
6 │ 0.497517 6 61
7 │ 0.355426 7 37
8 │ 0.834293 8 90
9 │ 0.258418 9 8
10 │ 0.0474276 10 37
julia> df[df.agerange .∈ Ref((1,8)), :]
2×3 DataFrame
Row │ income agerange count
│ Float64 Int64 Int64
─────┼───────────────────────────
1 │ 0.672059 1 44
2 │ 0.834293 8 90
julia> sum(df[df.agerange .∈ Ref((1,8)), :count])
134
thank you so much, in this “income” column, it has 2 kind of values: <=50K, 50K. I just want to take “count” values from them, and these values ∈ same “agerange” values.
Example: agerange : 19-31, Income >50K, count 1391 and
agerange : 19-31, Income <=50K, count 8945.
I want to get these values in general, do you have any
recipe for this
Anyway your code help me so much, thanks
you just need:
df[df.agerange .== "19-31", :count]
, if you don’t care about the Income column.
Again, I highly encourage you to read the manual because these basics mechanism you need to understand if you want to do anything.