Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Group by Period? | Working with Dates and Times in pandas
Dealing with Dates and Times in Python
course content

Зміст курсу

Dealing with Dates and Times in Python

Dealing with Dates and Times in Python

1. Working with Dates
2. Working with Times
3. Timezones and Daylight Savings Time (DST)
4. Working with Dates and Times in pandas

Challenge: Group by Period?

Previously, across other courses and chapters, you used to group observations by some columns. But can we do it with some time-series data? For example, can we summarize data by each week presented in dataset? Sounds like a complicated task.

Actually, pandas can handle even with that. There is .resample function available to group by different periods. Let's consider the structure of this function.

1
df.resample(rule, axis = 0, closed = None, label = None, convention = 'start', kind = None, loffset = None, base = None, on = None, level = None, origin = 'start_day', offset = None)
copy

The most important and the only one required argument is rule - the offset string or object representing target conversion. Easier, it's the period we want to divide our data by. There is a list of offset aliases used for resampling. You can find them in the table below the task.

Завдання

  1. Set pickup_datetime column of df dataframe as an index of df.
  2. Calculate the number of trips each month available in dataset.

Завдання

  1. Set pickup_datetime column of df dataframe as an index of df.
  2. Calculate the number of trips each month available in dataset.
AliasMeaning
BBusiness day frequency
CCustom business day frequency
DCalendar day frequency
WWeekly frequency
MMonth end frequency
QQuarter end frequency

There are many more aliases available. You can read about it in documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases (Offset aliases)

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

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

Секція 4. Розділ 10
toggle bottom row

Challenge: Group by Period?

Previously, across other courses and chapters, you used to group observations by some columns. But can we do it with some time-series data? For example, can we summarize data by each week presented in dataset? Sounds like a complicated task.

Actually, pandas can handle even with that. There is .resample function available to group by different periods. Let's consider the structure of this function.

1
df.resample(rule, axis = 0, closed = None, label = None, convention = 'start', kind = None, loffset = None, base = None, on = None, level = None, origin = 'start_day', offset = None)
copy

The most important and the only one required argument is rule - the offset string or object representing target conversion. Easier, it's the period we want to divide our data by. There is a list of offset aliases used for resampling. You can find them in the table below the task.

Завдання

  1. Set pickup_datetime column of df dataframe as an index of df.
  2. Calculate the number of trips each month available in dataset.

Завдання

  1. Set pickup_datetime column of df dataframe as an index of df.
  2. Calculate the number of trips each month available in dataset.
AliasMeaning
BBusiness day frequency
CCustom business day frequency
DCalendar day frequency
WWeekly frequency
MMonth end frequency
QQuarter end frequency

There are many more aliases available. You can read about it in documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases (Offset aliases)

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

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

Секція 4. Розділ 10
toggle bottom row

Challenge: Group by Period?

Previously, across other courses and chapters, you used to group observations by some columns. But can we do it with some time-series data? For example, can we summarize data by each week presented in dataset? Sounds like a complicated task.

Actually, pandas can handle even with that. There is .resample function available to group by different periods. Let's consider the structure of this function.

1
df.resample(rule, axis = 0, closed = None, label = None, convention = 'start', kind = None, loffset = None, base = None, on = None, level = None, origin = 'start_day', offset = None)
copy

The most important and the only one required argument is rule - the offset string or object representing target conversion. Easier, it's the period we want to divide our data by. There is a list of offset aliases used for resampling. You can find them in the table below the task.

Завдання

  1. Set pickup_datetime column of df dataframe as an index of df.
  2. Calculate the number of trips each month available in dataset.

Завдання

  1. Set pickup_datetime column of df dataframe as an index of df.
  2. Calculate the number of trips each month available in dataset.
AliasMeaning
BBusiness day frequency
CCustom business day frequency
DCalendar day frequency
WWeekly frequency
MMonth end frequency
QQuarter end frequency

There are many more aliases available. You can read about it in documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases (Offset aliases)

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

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

Previously, across other courses and chapters, you used to group observations by some columns. But can we do it with some time-series data? For example, can we summarize data by each week presented in dataset? Sounds like a complicated task.

Actually, pandas can handle even with that. There is .resample function available to group by different periods. Let's consider the structure of this function.

1
df.resample(rule, axis = 0, closed = None, label = None, convention = 'start', kind = None, loffset = None, base = None, on = None, level = None, origin = 'start_day', offset = None)
copy

The most important and the only one required argument is rule - the offset string or object representing target conversion. Easier, it's the period we want to divide our data by. There is a list of offset aliases used for resampling. You can find them in the table below the task.

Завдання

  1. Set pickup_datetime column of df dataframe as an index of df.
  2. Calculate the number of trips each month available in dataset.
AliasMeaning
BBusiness day frequency
CCustom business day frequency
DCalendar day frequency
WWeekly frequency
MMonth end frequency
QQuarter end frequency

There are many more aliases available. You can read about it in documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases (Offset aliases)

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 4. Розділ 10
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt