mchd
mchd

Reputation: 3163

Julia reporting an extra ) when it doesn't exist

I have this for loop in Julia:

begin
    countries_data_labels = ["Canada", "Italy", "China", "United States", "Spain"]
    y_axis = DataFrame()
    
    
    for country in countries_data_labels
        
        new_dataframe = get_country(df, country)
        
        new_dataframe = DataFrame(new_dataframe)
        
        df_rows, df_columns = size(new_dataframe)
        
        new_dataframe_long = stack(new_dataframe, begin:end-4)
        
        y_axis[!, Symbol("$country")] = new_dataframe_long[!, :value]
        
    end
end

and I'm getting this error:

syntax: extra token ")" after end of expression

I decided to comment all of the body of the for loop except the 1st one and ran the cell each time after uncommenting to see which line was throwing this error and it was the 4th line in the body:

new_dataframe_long = stack(new_dataframe, begin:end-4)

There is no reason for this error to exist. There are no extra bracket pieces in this line.

Upvotes: 3

Views: 270

Answers (1)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42234

My guess is that you mean here:

stack(new_dataframe[begin:end-4, :])

See the MWE example below:

julia> df = DataFrame(a=11:16,b=2.5:7.5)
6×2 DataFrame
 Row │ a      b
     │ Int64  Float64
─────┼────────────────
   1 │    11      2.5
   2 │    12      3.5
   3 │    13      4.5
   4 │    14      5.5
   5 │    15      6.5
   6 │    16      7.5

julia> stack(df[begin:end-3, :])
3×3 DataFrame
 Row │ a      variable  value
     │ Int64  String    Float64
─────┼──────────────────────────
   1 │    11  b             2.5
   2 │    12  b             3.5
   3 │    13  b             4.5

Upvotes: 5

Related Questions