From the course: Advanced Pandas
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Data type conversions using pandas
- [Instructor] One area where you might encounter some hurdles with pandas is dealing with data types. pandas is generally pretty good at assigning proper data types but, nonetheless, you'll find many instances when you need to convert data types. In this lesson, we'll leverage the planets dataset as it has a good variety of data types. After importing pandas, we'll read the planets data as a CSV. (typing) Now, let's have a peek at the data. From looking over the data frame, you can probably infer what the data type assignments will be, but to be sure we can access the dtypes attribute of planets. Now, we see data types varying from an object to integers to floats. How pandas handles your data depends on the data types you've designated. For example, we'll use the mean function to return the average for all float and integer values in our dataset. Everything looks pretty good, though you might question whether it…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.