The Most Profitable Periods
Good, now we know that the given data are weekly. Let's find out what weeks were the most profitable by comparing the total for each week.
Завдання
Swipe to start coding
- Group the observations in the
df
dataframe by the'Date'
column values. - Select the
'Weekly_Sales'
column. - Calculate the total (sum) for each group.
- Sort values in descending order (not ascending).
Рішення
9
1
2
3
4
5
6
7
8
9
# 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')
df['Date'] = pd.to_datetime(df['Date'], dayfirst = True)
# Inspecting the data
print(df.groupby('Date')['Weekly_Sales'].sum().sort_values(ascending = False))
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 3. Розділ 5
9
1
2
3
4
5
6
7
8
9
# 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')
df['Date'] = pd.to_datetime(df['Date'], dayfirst = True)
# Inspecting the data
print(___.___('___')['___'].___().___(ascending = ___))
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат