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

book
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

  1. Prepare the data for visualization: filter the values in the df so that only data for stores with the numbers present in the top_stores list remain. Save the resulting data in the data variable.
  2. 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.

Рішення

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

Запитати АІ

expand
ChatGPT

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

some-alt