Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Proper Converting | Preprocessing Data: Part II
Analyzing and Visualizing Real-World Data

book
Proper Converting

Fortunately, this issue can be easily fixed. The .to_datetime() method has yearfirst and dayfirst boolean parameters that define whether dates start with the year or day, respectively. By default, both parameters are set to False, which is why the first numbers were considered as months (if possible). Since the dates in our data start with the day, we just need to set the dayfirst parameter to True.

Завдання

Swipe to start coding

  1. Convert the 'Date' column to datetime type, considering that the day comes first.
  2. Output the first 5 rows and dtypes of the df dataframe.

Рішення

# 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')

# Change column type
df['Date'] = pd.to_datetime(df['Date'], dayfirst = True)

# Displaying first 5 rows and dtypes of dataframe
print(df.head())
print(df.dtypes)

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

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

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

Секція 2. Розділ 5
# 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')

# Change column type
df['Date'] = pd.___(df['___'], ___ = ___)

# Displaying first 5 rows and dtypes of dataframe
print(df.___())
print(df.___)

Запитати АІ

expand
ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt