Comparing Dynamics
Returning to the previous section, you solved the problem of finding the most profitable stores. According to the data, these stores are numbered 20, 4, 14, 13, and 2 (the numbers are saved in the top_stores
variable). Let's examine the sales dynamics of these stores.
Завдання
Swipe to start coding
- Prepare the data for visualization: filter the values in the
df
so that only data for stores with the numbers present in thetop_stores
list remain. Save the resulting data in thedata
variable. - Initialize a line plot with dates on the x-axis, weekly sales on the y-axis, using the
data
dataframe. Display a separate line for each store.
Рішення
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Loading the library
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# 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)
# Preparing the data
top_stores = [20, 4, 14, 13, 2]
data = df.loc[df['Store'].isin(top_stores)]
# Initializing the plot
plt.figure(figsize = (15, 3))
sns.lineplot(x = 'Date', y = 'Weekly_Sales', hue = 'Store', data = data)
# Displaying the plot
plt.show()
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 4. Розділ 2
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Loading the library
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# 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)
# Preparing the data
top_stores = [20, 4, 14, 13, 2]
data = df.___[___.___(___)]
# Initializing the plot
plt.figure(figsize = (15, 3))
sns.___(x = 'Date', y = 'Weekly_Sales', hue = '___', data = data)
# Displaying the plot
plt.show()
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат