update
This commit is contained in:
116
src/util.jl
Normal file
116
src/util.jl
Normal 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
|
||||
Reference in New Issue
Block a user