<i id='vGSxE'><tr id='vGSxE'><dt id='vGSxE'><q id='vGSxE'><span id='vGSxE'><b id='vGSxE'><form id='vGSxE'><ins id='vGSxE'></ins><ul id='vGSxE'></ul><sub id='vGSxE'></sub></form><legend id='vGSxE'></legend><bdo id='vGSxE'><pre id='vGSxE'><center id='vGSxE'></center></pre></bdo></b><th id='vGSxE'></th></span></q></dt></tr></i><div id='vGSxE'><tfoot id='vGSxE'></tfoot><dl id='vGSxE'><fieldset id='vGSxE'></fieldset></dl></div>
    <tfoot id='vGSxE'></tfoot>

    • <bdo id='vGSxE'></bdo><ul id='vGSxE'></ul>
    <legend id='vGSxE'><style id='vGSxE'><dir id='vGSxE'><q id='vGSxE'></q></dir></style></legend>

    1. <small id='vGSxE'></small><noframes id='vGSxE'>

    2. 如何按升序或降序对海运条形图进行排序

      How to Sort Seaborn barplot in ascending or descending order(如何按升序或降序对海运条形图进行排序)
        • <i id='1o3yJ'><tr id='1o3yJ'><dt id='1o3yJ'><q id='1o3yJ'><span id='1o3yJ'><b id='1o3yJ'><form id='1o3yJ'><ins id='1o3yJ'></ins><ul id='1o3yJ'></ul><sub id='1o3yJ'></sub></form><legend id='1o3yJ'></legend><bdo id='1o3yJ'><pre id='1o3yJ'><center id='1o3yJ'></center></pre></bdo></b><th id='1o3yJ'></th></span></q></dt></tr></i><div id='1o3yJ'><tfoot id='1o3yJ'></tfoot><dl id='1o3yJ'><fieldset id='1o3yJ'></fieldset></dl></div>

          <tfoot id='1o3yJ'></tfoot>
                <bdo id='1o3yJ'></bdo><ul id='1o3yJ'></ul>

                <small id='1o3yJ'></small><noframes id='1o3yJ'>

              • <legend id='1o3yJ'><style id='1o3yJ'><dir id='1o3yJ'><q id='1o3yJ'></q></dir></style></legend>
                  <tbody id='1o3yJ'></tbody>

                本文介绍了如何按升序或降序对海运条形图进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                EXCEL文件包含有关7000 Apple App Store的信息,如下所示

                这是我的代码->;

                import seaborn as sns
                import matplotlib.pyplot as plt
                import pandas as pd 
                apple_store_data = pd.read_excel(r'apple_store.xlsx')
                sns.barplot(data=apple_store_data,y='PrimaryGenre',x='AvgRating',color='g')
                plt.show()
                

                它给出如下输出->;

                推荐答案

                若要按字母顺序对栏进行排序,可以使用ordered=True使列categorical:

                import matplotlib.pyplot as plt
                import seaborn as sns
                import pandas as pd
                import numpy as np
                
                df = pd.DataFrame({'Genre': np.random.choice(['helium', 'neon', 'argon', 'krypton', 'xenon', 'radon', 'oganesson'], 50),
                                   'Rating': np.random.randint(1, 11, 50)})
                df['Genre'] = pd.Categorical(df['Genre'], ordered=True)
                ax = sns.barplot(data=df, y='Genre', x='Rating', palette='husl')
                ax.tick_params(axis='y', length=0)
                plt.tight_layout()
                plt.show()
                

                要按降序排列条形图,可以使用以下代码。在这种情况下,不需要将该列设置为绝对列。

                ax = sns.barplot(data=df, y='Genre', x='Rating', palette='plasma',
                                 order=df.groupby('Genre')['Rating'].agg('mean').sort_values(ascending=False).index)
                

                ps:要仅显示例如前5名,请使用... .index[:5]

                ax = sns.barplot(data=df, y='Genre', x='Rating', palette='plasma',
                                 order=df.groupby('Genre')['Rating'].agg('mean').sort_values(ascending=False).index[:5])
                

                这篇关于如何按升序或降序对海运条形图进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)

                    • <small id='IxIZi'></small><noframes id='IxIZi'>

                        <bdo id='IxIZi'></bdo><ul id='IxIZi'></ul>
                        <legend id='IxIZi'><style id='IxIZi'><dir id='IxIZi'><q id='IxIZi'></q></dir></style></legend>
                            <tbody id='IxIZi'></tbody>
                        1. <tfoot id='IxIZi'></tfoot>

                        2. <i id='IxIZi'><tr id='IxIZi'><dt id='IxIZi'><q id='IxIZi'><span id='IxIZi'><b id='IxIZi'><form id='IxIZi'><ins id='IxIZi'></ins><ul id='IxIZi'></ul><sub id='IxIZi'></sub></form><legend id='IxIZi'></legend><bdo id='IxIZi'><pre id='IxIZi'><center id='IxIZi'></center></pre></bdo></b><th id='IxIZi'></th></span></q></dt></tr></i><div id='IxIZi'><tfoot id='IxIZi'></tfoot><dl id='IxIZi'><fieldset id='IxIZi'></fieldset></dl></div>