Thank you all, I appreciate your interest in my question.
You can download the original .csv
file from here.
In case of need, how would you suggest I share a file with you? I guess itโs not possible to share files here in the forum, right? Any platform you recommend for this kind of cases?
My guess is that the problem has to do with the encoding of some special characters, in particular the โ+โ sign.
I updated my OS today and currently only the data frame read from the original .csv
file shows the problem. Here are the tests I ran.
Iโll use the following helper function, to make testing easier:
function year_created(df, lang::String)
res = df[:, 1][lowercase.(df[:, 2]) .== lowercase(lang)]
!isempty(res) && return only(res)
error("Could not find the programming language.")
end
- Testing on the
.csv
file mentioned above (FAIL)
NOTE: I saved the file as โplangs01.csvโ.
julia> df1 = CSV.read("plangs01.csv", DataFrame)
73ร2 DataFrame
Row โ year plang
โ Int64 String31
โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 โ 1951 Regional Assembly Language
2 โ 1952 Autocode
3 โ 1954 IPL
โฎ โ โฎ โฎ
70 โ 2011 Red
71 โ 2011 Elixir
72 โ 2012 Julia
73 โ 2014 Swift
julia> year_created(df1, "julia")
2012
julia> year_created(df1, "c++")
ERROR: Could not find the programming language.
Stacktrace:
[1] year_created(df::DataFrame, lang::String)
@ Main ./REPL[101]:4
[2] top-level scope
@ REPL[109]:1
julia> year_created(df1, "c#")
2001
- Testing on a fresh data frame (PASS)
julia> df2 = DataFrame(
year = [1993, 1991, 1984, 1957, 1972, 1980, 2012],
lang = ["R", "Python", "MATLAB", "FORTRAN", "C", "C++", "Julia"]
)
7ร2 DataFrame
Row โ year lang
โ Int64 String
โโโโโโผโโโโโโโโโโโโโโโโ
1 โ 1993 R
2 โ 1991 Python
3 โ 1984 MATLAB
4 โ 1957 FORTRAN
5 โ 1972 C
6 โ 1980 C++
7 โ 2012 Julia
julia> year_created(df2, "JUlia")
2012
julia> year_created(df2, "c++")
1980
- Testing on a newly created
.csv
file (PASS)
julia> str = """
"year","lang"
1993,R
1991,Python
1984,Matlab
1957,Fortran
1972,C
1980,C++
2001,C#
2012,Julia
"""
"\"year\",\"lang\"\n1993,R\n1991,Python\n1984,Matlab\n1957,Fortran\n1972,C\n1980,C++\n2001,C#\n2012,Julia\n"
julia> open("plangs03.csv", "w") do file
write(file, str)
end
93
julia> df3 = CSV.read("plangs03.csv", DataFrame)
8ร2 DataFrame
Row โ year lang
โ Int64 String7
โโโโโโผโโโโโโโโโโโโโโโโ
1 โ 1993 R
2 โ 1991 Python
3 โ 1984 Matlab
4 โ 1957 Fortran
5 โ 1972 C
6 โ 1980 C++
7 โ 2001 C#
8 โ 2012 Julia
julia> year_created(df3, "julia")
2012
julia> year_created(df3, "c++")
1980
julia> year_created(df3, "c#")
2001
Iโm curious to know what your Test 1 results areโฆ
@rocco_sprmnt21, as you can see from my Test 3, your example is currently working for me, but I used to have the same problem youโre reporting.