4

Is there a standard naming convention that is suggestible for columns in Pandas Dataframes ?

As I looked around, this seems to be the most relevant question or answer on this topic: Pandas DataFrame column naming conventions. I couldn't find anything on PEP8 from quick glances. The solution provided here offers some general advice but no standard leaving it to the developer's prerogative.

import pandas as pd

col_names =  ['MyColumn1', 'Mycolumn2']
my_df  = pd.DataFrame(columns = col_names)

It looks like snake case looks appropriate from my personal perspective, but I want to know what is the standard and if PEP8 has any guidance.

2
  • 1
    I would just follow the same naming conventions for variables as laid out in PEP8 i don't know of any specific rules just for Pandas but if someone does please correct me. Also of course avoid any reserved keywords in python as well Commented Oct 28, 2019 at 0:38
  • As long as it does not contains space and special characters, it's fine. And you can always follow the same principal as naming variables in PEP8, just use snake_case. Commented Oct 28, 2019 at 2:31

1 Answer 1

0

It is really up to you how you name the columns as it is application- or problem specific. At least PEP8 does not care about this and a linter such as flake8 will not complain.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.