This commit is contained in:
narawat lamaiin
2024-08-28 05:56:25 +07:00
commit 1739972440
14 changed files with 3986 additions and 0 deletions

116
src/util.jl Normal file
View File

@@ -0,0 +1,116 @@
module util
export getDataFrameValue, dfRowtoString, dfToString
using DataFrames
""" get a value from a dataframe row by a given key
"""
getDataFrameValue(row::DataFrameRow, key::Symbol) = row.:($key)
""" convert df row into key:value string
"""
function dfRowtoString(row::DataFrameRow)::String
str = ""
for key in keys(row)
value = getDataFrameValue(row, key)
str *= "$key: $value, "
end
result = str[1:end-2] # remove ", " at the end of row
return result
end
""" convert df table into string
"""
function dfToString(df::DataFrame)
dfstr = ""
for (i, row) in enumerate(eachrow(df))
rowstr = dfRowtoString(row)
dfstr *= "$i) $rowstr\n"
end
return dfstr
end
end # module util