Type Conversion
Learn how to convert between types in pandas.
We'll cover the following
Why should we care about type?
- Reduce memory usage: Generally speaking, the numerical value would be regarded as
float64
orint64
. In most cases, this is OK. However, imagine you have, say, 50 million rows, but the columns will only store numbers from 0 to 20.int8
is quite enough in this case and saves a lot of memory. - Unmatched type: As mentioned above, the numerical value would be regarded as float64 or int64. In most cases, it’s ok. However, if one column is an ID column, obviously, float64 is not a suitable type.
- Specifical type: Datetime is one special case. If you don’t specify it, the Datetime would be regarded as an object type.
Get hands-on with 1400+ tech skills courses.