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
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
\twith\n.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.
Check the result
Spaces, hyphens and camelCase boundaries all become underscores, and everything is lowercase.
emailAddressis correctly split intoemail_address, andZIP codebecomeszip_code.first_name last_name email_address date_of_birth phone_number zip_codeUse the names
Copy the list back into your spreadsheet as the new header row, or use the names in a
CREATE TABLEstatement or a pandasrenamecall. For JavaScript or Java code, choose camelCase instead to getfirstName,lastNameand so on.
Try it yourself
Opens the Case Converter with this tutorial's sample loaded.
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_mailandemail, which are different. But "First name" and "first-name" both becomefirst_name. Check for clashes before importing. - Forgetting reserved words
- Some names, such as
order,grouporuser, 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.