This commit is contained in:
narawat lamaiin
2024-12-09 20:29:28 +07:00
parent 159d1717a4
commit d4895a728d
27 changed files with 7742 additions and 4002 deletions

View File

@@ -1,116 +1,80 @@
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
module util
end # module util