zoukankan      html  css  js  c++  java
  • Python数据分析与机器学习-Matplot_3

    import pandas as pd 
    reviews = pd.read_csv('fandango_scores.csv')
    cols = ['FILM','RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']
    norm_reviews = reviews[cols]
    print(norm_reviews)
    
                                                   FILM  RT_user_norm  
    0                    Avengers: Age of Ultron (2015)          4.30   
    1                                 Cinderella (2015)          4.00   
    2                                    Ant-Man (2015)          4.50   
    3                            Do You Believe? (2015)          4.20   
    4                     Hot Tub Time Machine 2 (2015)          1.40   
    5                          The Water Diviner (2015)          3.10   
    6                             Irrational Man (2015)          2.65   
    7                                   Top Five (2014)          3.20   
    8                      Shaun the Sheep Movie (2015)          4.10   
    9                               Love & Mercy (2015)          4.35   
    10                Far From The Madding Crowd (2015)          3.85   
    11                                 Black Sea (2015)          3.00   
    12                                 Leviathan (2014)          3.95   
    13                                  Unbroken (2014)          3.50   
    14                        The Imitation Game (2014)          4.60   
    15                                   Taken 3 (2015)          2.30   
    16                                     Ted 2 (2015)          2.90   
    17                                  Southpaw (2015)          4.00   
    18   Night at the Museum: Secret of the Tomb (2014)          2.90   
    19                                    Pixels (2015)          2.70   
    20                            McFarland, USA (2015)          4.45   
    21                      Insidious: Chapter 3 (2015)          2.80   
    22                   The Man From U.N.C.L.E. (2015)          4.00   
    23                             Run All Night (2015)          2.95   
    24                                Trainwreck (2015)          3.70   
    25                                     Selma (2014)          4.30   
    26                                Ex Machina (2015)          4.30   
    27                               Still Alice (2015)          4.25   
    28                                Wild Tales (2014)          4.60   
    29                       The End of the Tour (2015)          4.45   
    ..                                              ...           ...   
    116                     Clouds of Sils Maria (2015)          3.35   
    117                       Testament of Youth (2015)          3.95   
    118                    Infinitely Polar Bear (2015)          3.80   
    119                                  Phoenix (2015)          4.05   
    120                             The Wolfpack (2015)          3.65   
    121           The Stanford Prison Experiment (2015)          4.35   
    122                                Tangerine (2015)          4.30   
    123                           Magic Mike XXL (2015)          3.20   
    124                                     Home (2015)          3.25   
    125                       The Wedding Ringer (2015)          3.30   
    126                            Woman in Gold (2015)          4.05   
    127                      The Last Five Years (2015)          3.00   
    128     Mission: Impossible – Rogue Nation (2015)          4.50   
    129                                      Amy (2015)          4.55   
    130                           Jurassic World (2015)          4.05   
    131                                  Minions (2015)          2.60   
    132                                      Max (2015)          3.65   
    133                   Paul Blart: Mall Cop 2 (2015)          1.80   
    134                         The Longest Ride (2015)          3.65   
    135                       The Lazarus Effect (2015)          1.15   
    136      The Woman In Black 2 Angel of Death (2015)          1.25   
    137                            Danny Collins (2015)          3.75   
    138                              Spare Parts (2015)          4.15   
    139                                   Serena (2015)          1.25   
    140                               Inside Out (2015)          4.50   
    141                               Mr. Holmes (2015)          3.90   
    142                                      '71 (2015)          4.10   
    143                      Two Days, One Night (2014)          3.90   
    144       Gett: The Trial of Viviane Amsalem (2015)          4.05   
    145              Kumiko, The Treasure Hunter (2015)          3.15   
    
         Metacritic_user_nom  IMDB_norm  Fandango_Ratingvalue  Fandango_Stars  
    0                   3.55       3.90                   4.5             5.0  
    1                   3.75       3.55                   4.5             5.0  
    2                   4.05       3.90                   4.5             5.0  
    3                   2.35       2.70                   4.5             5.0  
    4                   1.70       2.55                   3.0             3.5  
    5                   3.40       3.60                   4.0             4.5  
    6                   3.80       3.45                   3.5             4.0  
    7                   3.40       3.25                   3.5             4.0  
    8                   4.40       3.70                   4.0             4.5  
    9                   4.25       3.90                   4.0             4.5  
    10                  3.75       3.60                   4.0             4.5  
    11                  3.30       3.20                   3.5             4.0  
    12                  3.60       3.85                   3.5             4.0  
    13                  3.25       3.60                   4.1             4.5  
    14                  4.10       4.05                   4.6             5.0  
    15                  2.30       3.05                   4.1             4.5  
    16                  3.25       3.30                   4.1             4.5  
    17                  4.10       3.90                   4.6             5.0  
    18                  2.90       3.15                   4.1             4.5  
    19                  2.65       2.80                   4.1             4.5  
    20                  3.60       3.75                   4.6             5.0  
    21                  3.45       3.15                   4.1             4.5  
    22                  3.95       3.80                   4.1             4.5  
    23                  3.65       3.30                   4.1             4.5  
    24                  3.00       3.35                   4.1             4.5  
    25                  3.55       3.75                   4.6             5.0  
    26                  3.95       3.85                   4.1             4.5  
    27                  3.90       3.75                   4.1             4.5  
    28                  4.40       4.10                   4.1             4.5  
    29                  3.75       3.95                   4.1             4.5  
    ..                   ...        ...                   ...             ...  
    116                 3.55       3.40                   3.4             3.5  
    117                 3.95       3.65                   3.9             4.0  
    118                 3.95       3.60                   3.9             4.0  
    119                 4.00       3.60                   3.4             3.5  
    120                 3.50       3.55                   3.4             3.5  
    121                 4.25       3.55                   3.9             4.0  
    122                 3.65       3.70                   3.9             4.0  
    123                 2.70       3.15                   4.4             4.5  
    124                 3.65       3.35                   4.4             4.5  
    125                 1.65       3.35                   4.4             4.5  
    126                 3.60       3.70                   4.4             4.5  
    127                 3.45       3.00                   4.4             4.5  
    128                 4.00       3.90                   4.4             4.5  
    129                 4.40       4.00                   4.4             4.5  
    130                 3.50       3.65                   4.5             4.5  
    131                 2.85       3.35                   4.0             4.0  
    132                 2.95       3.50                   4.5             4.5  
    133                 1.20       2.15                   3.5             3.5  
    134                 2.40       3.60                   4.5             4.5  
    135                 2.45       2.60                   3.0             3.0  
    136                 2.20       2.45                   3.0             3.0  
    137                 3.55       3.55                   4.0             4.0  
    138                 3.55       3.60                   4.5             4.5  
    139                 2.65       2.70                   3.0             3.0  
    140                 4.45       4.30                   4.5             4.5  
    141                 3.95       3.70                   4.0             4.0  
    142                 3.75       3.60                   3.5             3.5  
    143                 4.40       3.70                   3.5             3.5  
    144                 3.65       3.90                   3.5             3.5  
    145                 3.20       3.35                   3.5             3.5  
    
    [146 rows x 6 columns]
    
    import matplotlib.pyplot as plt
    from numpy import arange
    # The Axes.bar() method has 2 required parameters, left and height.
    # We use the left parameter to specify the x coordinates of the left sides of the bar.
    # We use the height parameter to specify the height of each bar
    num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']
    bar_heights = norm_reviews.loc[0,num_cols].values
    print(bar_heights)
    bar_positions = arange(5)+0.75
    print(bar_positions)
    fig, ax = plt.subplots()
    ax.bar(bar_positions,bar_heights,0.5)
    plt.show()
    
    [4.3 3.55 3.9 4.5 5.0]
    [0.75 1.75 2.75 3.75 4.75]
    

    # By default, matplotlib sets the x-axis tick labels to the integer values the bars 
    # spanned on the x-axis (from 0 to 6). We only need tick labels on the x-axis where the bars are positioned. 
    # We can use Axes.set_xticks() to change the positions of the ticks to [1, 2, 3, 4, 5]:
    num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']
    bar_heights = norm_reviews.loc[0, num_cols].values
    bar_positions = arange(5) + 0.75
    tick_positions = range(1,6)
    print(tick_positions)
    fig, ax = plt.subplots()
    ax.bar(bar_positions,bar_heights,0.5)
    ax.set_xticks(tick_positions)
    ax.set_xticklabels(num_cols,rotation=45)
    
    ax.set_xlabel('Rating Source')
    ax.set_ylabel('Average Rating')
    ax.set_title('Average User Rating For Avengers: Age of Ultron (2015)')
    plt.show()
    
    range(1, 6)
    

    import matplotlib.pyplot as plt
    from numpy import arange
    num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']
    
    bar_widths = norm_reviews.loc[0, num_cols].values
    bar_positions = arange(5) + 0.75
    tick_positions = range(1,6)
    fig, ax = plt.subplots()
    ax.barh(bar_positions, bar_widths, 0.5)
    
    ax.set_yticks(tick_positions)
    ax.set_yticklabels(num_cols)
    ax.set_ylabel('Rating Source')
    ax.set_xlabel('Average Rating')
    ax.set_title('Average User Rating For Avengers: Age of Ultron (2015)')
    plt.show()
    

    # Let's look at a plot that can help us visualize many points
    fig, ax = plt.subplots()
    ax.scatter(norm_reviews['Fandango_Ratingvalue'],norm_reviews['RT_user_norm'])
    ax.set_xlabel('Fandango')
    ax.set_ylabel('Rotten Tomatoes')
    plt.show()
    

    # Switching Axes
    fig = plt.figure(figsize=(5,10))
    ax1 = fig.add_subplot(2,1,1)
    ax2 = fig.add_subplot(2,1,2)
    ax1.scatter(norm_reviews['Fandango_Ratingvalue'],norm_reviews['RT_user_norm'])
    ax1.set_xlabel('Fandango')
    ax1.set_ylabel('Rotten Tomatoes')
    ax2.scatter(norm_reviews['RT_user_norm'],norm_reviews['Fandango_Ratingvalue'])
    ax2.set_xlabel('Rotten Tomatoes')
    ax2.set_ylabel('Fandango')
    plt.show()
    

  • 相关阅读:
    4 行代码实现将文件读到 C++ string
    Adaptive AUTOSAR 学习笔记 15
    Adaptive AUTOSAR 学习笔记 14
    Adaptive AUTOSAR 学习笔记 13
    Adaptive AUTOSAR 学习笔记 12
    Adaptive AUTOSAR 学习笔记 10
    Adaptive AUTOSAR 学习笔记 9
    Linux 彻底卸载从源码安装的 boost 库
    Adaptive AUTOSAR 学习笔记 8
    grep awk sed 正则表达式,只把匹配的内容(不是整个匹配行)提取出来,保存到 shell 脚本变量
  • 原文地址:https://www.cnblogs.com/SweetZxl/p/11126864.html
Copyright © 2011-2022 走看看