简体   繁体   English

前 5 列,共 2 列

[英]Top 5 of 2 columns

I would like to Display side by side two graphs containing the top 5 most popular French series and the top 5 most popular French films.我想并排显示两个图表,其中包含前 5 部最受欢迎的法国剧集和前 5 部最受欢迎的法国电影。

The number of votes numVotes for a series or a movie will be considered as a reliable indicator of its popularity.系列或电影的票数 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()

You can take the subset of top_france_tv that are movies, then sort by averageRating and take the first 5. Use this as the dataframe for a barplot showing title and averageRating .您可以将top_france_tv的子集作为电影,然后按averageRating排序并取前 5 个。将此作为barplot用于显示titleaverageRating的条形图。 Repeat for the tv shows.重复电视节目。

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