Session Ready
Exercise

Integers and floats

Remember you can use the type() function to see the data type of an object? However, this information is insufficient when working with DataFrames, since the result will be:

print(type(some_DataFrame))

<class 'pandas.core.frame.DataFrame'>

If you want to find out the data type of each column in the DataFrame, you can either use the .info() method or the .dtypes attribute. Now, if you want to change the data type of a column, you can call the .astype() method on the column along with the new type for the column. For example, to convert the type of 'column_a' to integer:

df['column_a'] = df['column_a'].astype(int)
Instructions
100 XP
  • Inspect the output of tips.dtypes in the shell.
  • Convert the size column to int type.
  • Convert the tip columns to float type.
  • Look at .dtypes again.