Files
SQLLLM/previousVersion/0.1/src/util.jl
narawat lamaiin d4895a728d update
2024-12-09 20:29:28 +07:00

116 lines
912 B
Julia

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