5

Datafrme as follows:

julia> df3
8×6 DataFrame
│ Row │ RegionID │ RegionName   │ StateName    │ SizeRank │ 2008-03 │ 2008-04 │
│     │ Any      │ Any          │ Any          │ Any      │ Any     │ Any     │
├─────┼──────────┼──────────────┼──────────────┼──────────┼─────────┼─────────┤
│ 1   │ 6181     │ New York     │ New York     │ 1        │ missing │ missing │
│ 2   │ 12447    │ Los Angeles  │ California   │ 2        │ 1446    │ 1705    │
│ 3   │ 39051    │ Houston      │ Texas        │ 3        │ 2926    │ 3121    │
│ 4   │ 17426    │ Chicago      │ Illinois     │ 4        │ 2910    │ 3022    │
│ 5   │ 6915     │ San Antonio  │ Texas        │ 5        │ 1479    │ 1529    │
│ 6   │ 13271    │ Philadelphia │ Pennsylvania │ 6        │ 1609    │ 1795    │
│ 7   │ 40326    │ Phoenix      │ Arizona      │ 7        │ 1310    │ 1519    │
│ 8   │ 18959    │ Las Vegas    │ Nevada       │ 8        │ 1618    │ 1856    │

Throws error while selecting the rows where StateName is equal to Arizona, as follows:

julia> filter(:StateName => ==("Arizona"), df3)
ERROR: MethodError: objects of type Pair{Symbol,Base.Fix2{typeof(==),String}} are not callable
Stacktrace:
 [1] (::DataFrames.var"#53#54"{Pair{Symbol,Base.Fix2{typeof(==),String}}})(::DataFrameRow{DataFrame,DataFrames.Index}) at ./none:0
 [2] iterate at ./generator.jl:47 [inlined]
 [3] collect at ./array.jl:665 [inlined]
 [4] filter(::Pair{Symbol,Base.Fix2{typeof(==),String}}, ::DataFrame) at /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/packages/DataFrames/yH0f6/src/abstractdataframe/abstractdataframe.jl:758
 [5] top-level scope at REPL[102]:1

Please guide me in selecting the rows where StateName is equal to Arizona.

AVA
  • 2,474
  • 2
  • 26
  • 41

1 Answers1

7

Please update your DataFrames.jl to the latest version (currently 1.2). You are on pre 1.0 release version. If you have to stick to your version do:

filter(row -> row.StateName == "Arizona", df3)

or just

df3[df3.StateName .== "Arizona", :]
Bogumił Kamiński
  • 66,844
  • 3
  • 80
  • 107