Converting Data Types
Another problem you may face in a project is incorrect data types being inferred for some columns. As we saw in Chapter 10, Analyzing a Dataset, the pandas
package provides us with a very easy way to display the data type of each column using the .dtypes
attribute. You may be wondering, when did pandas
identify the type of each column? The types are detected when you load the dataset into a pandas
DataFrame using methods such as read_csv()
, read_excel()
, and so on.
When you've done this, pandas
will try its best to automatically find the best type according to the values contained in each column. Let's see how this works on the Online Retail
dataset.
First, you must import pandas
:
import pandas as pd
Then, you need to assign the URL to the dataset to a new variable:
file_url = 'https://github.com/PacktWorkshops/'\ 'The-Data-Science-Workshop/blob/'\ ...