簡體   English   中英

前 5 列,共 2 列

[英]Top 5 of 2 columns

我想並排顯示兩個圖表,其中包含前 5 部最受歡迎的法國劇集和前 5 部最受歡迎的法國電影。

系列或電影的票數 numVotes 將被視為其受歡迎程度的可靠指標。

top_france_tv = pd.Series(df[df['country'] == 'France']

ax = sns.countplot(y=top_france_tv, order=top_france_tv.value_counts().iloc[:5].index)

ax.tick_params(axis='y', length=0)

plt.tight_layout()

plt.show()

您可以將top_france_tv的子集作為電影,然后按averageRating排序並取前 5 個。將此作為barplot用於顯示titleaverageRating的條形圖。 重復電視節目。

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import seaborn as sns

sns.set()
np.random.seed(123)
df = pd.DataFrame({'type': np.random.choice(['Movie', 'TV Show'], 100),
                   'title': ["".join(np.random.choice([*'uvwxyz '], np.random.randint(5, 20))) for _ in range(100)],
                   'averageRating': np.random.uniform(1, 10, 100).round(1),
                   'country': np.random.choice(['France', 'other country'], 100)})
top_france_tv = df[df['country'] == 'France']
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12, 3), sharex=True)
for ax, mov_type in zip((ax1, ax2), ['Movie', 'TV Show']):
    df_best_5 = top_france_tv[top_france_tv['type'] == mov_type].sort_values('averageRating', ascending=False)[:5]
    sns.barplot(data=df_best_5, y='title', x='averageRating', palette='rocket', ax=ax)
    ax.set_title('Best 5 French ' + mov_type + 's')
    ax.set_ylabel('')
plt.tight_layout()
plt.show()

找到 5 個最好的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM