Case Converter · Tutorial

How to convert spreadsheet column names to snake_case

4 min readbeginnerUpdated

You're importing a spreadsheet into a database or a Python script, and the column headers are a mix of styles. Some have spaces, some are camelCase, some use hyphens. Databases and code work best with consistent snake_case names. This tutorial converts a whole list of headers in one go.

What you need

  • The Case Converter
  • Your column headers, one per line (the Try it button loads six typical headers)

Steps

  1. Copy the headers as a list

    In your spreadsheet, copy the header row. When you paste it, each header should be on its own line. If they arrive on a single line separated by tabs, put each one on a new line first, for example with Find and Replace, replacing \t with \n.

  2. Paste and choose snake_case

    Paste the list into the left box and choose snake_case from Convert to. Each line is converted separately, so every header gets its own name.

  3. Check the result

    Spaces, hyphens and camelCase boundaries all become underscores, and everything is lowercase. emailAddress is correctly split into email_address, and ZIP code becomes zip_code.

    first_name
    last_name
    email_address
    date_of_birth
    phone_number
    zip_code
  4. Use the names

    Copy the list back into your spreadsheet as the new header row, or use the names in a CREATE TABLE statement or a pandas rename call. For JavaScript or Java code, choose camelCase instead to get firstName, lastName and so on.

Try it yourself

Opens the Case Converter with this tutorial's sample loaded.

Try it now

Common mistakes

Pasting headers on one line
Identifier cases are applied per line. If all headers are on one line, they become one long name like first_name_last_name_email.
Ignoring duplicates
Two headers like "E-mail" and "Email" both become e_mail and email, which are different. But "First name" and "first-name" both become first_name. Check for clashes before importing.
Forgetting reserved words
Some names, such as order, group or user, are reserved in SQL. Add a prefix or quote them in your database.

Next steps

Go back to the Case Converter, or keep going with one of these:

FAQ

Can I convert names back to readable labels?

Yes. Paste the snake_case names and choose Title Case to get labels like "First Name" for forms and reports.