Type Conversion
Explore how to manage and convert data types in Pandas to optimize memory usage and ensure data integrity. Learn to use astype, lambda functions, and specialized functions like to_datetime to handle numerical, string, and datetime data. Understand setting data types during CSV import for better performance.
We'll cover the following...
We'll cover the following...
Why should we care about type?
- Reduce memory usage: Generally speaking, the numerical value would be regarded as
float64orint64. 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.int8is quite enough in this case and saves a lot of memory. - Unmatched type: As mentioned above, the numerical value would be regarded as