I am trying to find a way to name columns of a dataframe using strings coming from excel or scraping the web.
So how to transform "colname" to colname below?
df = DataFrame(colname = [1, 2])
I tried
df = DataFrame(symbol("colname") = [1, 2])
or
df = DataFrame([1, 2], [symbol("colname")])
and many other combinations, but no success. I see questions related to deleting columns based on string column names but no question/answer for naming columns in the first place.
May be you can try something like this in two steps using the names!
function.
using DataFrames
newname = ["colname1", "colname2"]
df = DataFrame(v1 = [1, 2], v2 = [3, 4])
names!(df.colindex, map(parse, newname))
df
# 2x2 DataFrames.DataFrame
# | Row | colname1 | colname2 |
# |-----|----------|----------|
# | 1 | 1 | 3 |
# | 2 | 2 | 4 |
Here are the version of Julia
and DataFrames.jl
I used
versioninfo()
# Julia Version 0.4.0-dev+6991
# Commit 811a977 (2015-08-26 04:02 UTC)
# Platform Info:
# System: Linux (x86_64-unknown-linux-gnu)
# CPU: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
# WORD_SIZE: 64
# BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
# LAPACK: libopenblas
# LIBM: libopenlibm
# LLVM: libLLVM-svn
Pkg.installed("DataFrames")
# v"0.6.9"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With