Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer normalizenames? #260

Open
nilshg opened this issue May 22, 2024 · 0 comments
Open

Offer normalizenames? #260

nilshg opened this issue May 22, 2024 · 0 comments

Comments

@nilshg
Copy link

nilshg commented May 22, 2024

I often find myself doing:

df = DataFrame(XLSX.readtable("myfile.xlsx", 1))

# Realize column names are whacky

using CSV

rename!(df, CSV.normalizenames(names(df)))

Which isn't too much hassle but I was wondering whether we should just copy over those seven lines:

normalizename(name::Symbol) = name
function normalizename(name::String)::Symbol
    uname = strip(Unicode.normalize(name))
    id = Base.isidentifier(uname) ? uname : map(c->Base.is_id_char(c) ? c : '_', uname)
    cleansed = string((isempty(id) || !Base.is_id_start_char(id[1]) || id in RESERVED) ? "_" : "", id)
    return Symbol(replace(cleansed, r"(_)\1+"=>"_"))
end

to somewhere in XLSX.jl and expose a keyword?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant