43  Tips for recognizing the data types

Author

Paschalis Agapitos

43.1 Good practise

A very good practise when we try to change the data type of a variable is to try to align it with its real-world variable data type. Therefore, if it is continuous, then use floats; if it is discrete then use integers.

Type of variable Data type
continuous variable float
discrete variable integer

What is happening with the miscellaneous variables? For example the money can be both measured continuously or discretely. Continuously by measuring it in fractions. Discretely by counting it in cents since money can’t be divided in something less than cents.

This is the reason we should always connect the variable type with the real-world variable data type, thus we need to take a close look to the context.

Using the command:

data.dtypes
  • data: is the name of our dataset/ dataframe.

We take a close look to the data types of each column.

After that, by using the command .astype() we can change the value of each column if needed.