Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Processing Dates | Preprocessing Data: Part II
Analyzing and Visualizing Real-World Data
course content

Зміст курсу

Analyzing and Visualizing Real-World Data

Analyzing and Visualizing Real-World Data

1. Preprocessing Data: Part I
2. Preprocessing Data: Part II
3. Analyzing Data
4. Visualizing Data

bookProcessing Dates

We are close to finishing! Let's see what data types our data has now.

12345678
# Loading the library import pandas as pd # Reading the data df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/72be5dde-f3e6-4c40-8881-e1d97ae31287/shops_data3.csv') # Checking columns types print(df.dtypes)
copy

As you can see, there is only one object column left. You may be wondering why this is bad. Actually, we can leave it as is, but pandas provides us with tools to work with dates and times. Unfortunately, datetime is not a built-in data type in Python, so we can't convert the column and save it. We will have to convert it after loading every time. To convert to datetime type, we need to use the .to_datetime() method of pd.

123456789101112131415
# Loading the library import pandas as pd # Reading the data df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/72be5dde-f3e6-4c40-8881-e1d97ae31287/shops_data3.csv') # Displaying first four dates before converting print(df['Date'].head(4)) # Change column type df['Date'] = pd.to_datetime(df['Date']) # Displaying first four dates and dtypes of dataframe print(df['Date'].head(4)) print(df.dtypes)
copy

As you can see, visually the dates have changed, i.e., they are now represented in a different format.

What is the initial format of dates in the `'Date'` column? *(dd - day, mm - month, yyyy - year)*

What is the initial format of dates in the 'Date' column? (dd - day, mm - month, yyyy - year)

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 3
some-alt