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

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.

question mark

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

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 2.  3

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 2.  3
some-alt