Should dataframe column names always be capitalized?

Question

In Pandas, should dataframe column names always be capitalized?

Answer

The short answer is, no. Column names in Pandas dataframes do not always have to be capitalized, and there is no strict requirement on how to case your column names.

However, there are a few important points you might keep in mind when you are naming columns for Pandas dataframes.

  • One point which also applies to Python in general, is that column name casing should usually be consistent. If you decide to capitalize one column name, then it might be good to capitalize all column names to stay consistent. This applies when naming variables, functions and almost anything else in Python.

  • One additional point is that when naming the columns, consider using “snake_case”, which uses casing in the form that this convention implies. This is because, it will give you the freedom to select columns of a dataframe using either format:
    df.column_name or df['column_name']

4 Likes

Can you please specify what does ‘Snake Case’ means @jephos249.

2 Likes

It is just an example. Could have used car_park as an example too

2 Likes

Ohh yes…Thanx for mentioning that…Silly me :man_facepalming:

2 Likes

Snake Case is a naming convention used in python which says that when a variable name has more than one word, the words should be separated by an underscore “_”.

so if we have a variable for first name it would be first_name
last name would be last_name
the scary cat would be the_scary_cat

An alternative naming convention is the Camel case which is use javascript where we do not separate words of a variable name but we write the first word in small letters and capitalize the first letter of subsequent words of the variable name.

so if we have a variable for first name it would be firstName
last name would be lastName
the scary cat would be theScaryCat

2 Likes