Search code examples
pythonpandasmatplotlibseaborndata-analysis

How to get a boxplot of each category in a single figure


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

dftrain = pd.read_csv('laptop_price_train.csv', encoding = 'latin-1')

ytrain = dftrain.pop('Price_euros')

#This is the plot I want to make
pd.concat([dftrain['Company'], ytrain], axis = 1).groupby('Company').plot(kind = 'box').set_xlabel()

The box plot I am getting is individual box plots of each company. I want the plot to show the boxplots to look like this:

enter image description here

Data

Selected columns from this dataset on Kaggle.

# dftrain.head()
   laptop_ID Company      Product   TypeName  Inches                    ScreenResolution                         Cpu   Ram               Memory                           Gpu  OpSys  Weight  Price_euros
0          1   Apple  MacBook Pro  Ultrabook    13.3  IPS Panel Retina Display 2560x1600        Intel Core i5 2.3GHz   8GB            128GB SSD  Intel Iris Plus Graphics 640  macOS  1.37kg      1339.69
1          2   Apple  Macbook Air  Ultrabook    13.3                            1440x900        Intel Core i5 1.8GHz   8GB  128GB Flash Storage        Intel HD Graphics 6000  macOS  1.34kg       898.94
2          3      HP       250 G6   Notebook    15.6                   Full HD 1920x1080  Intel Core i5 7200U 2.5GHz   8GB            256GB SSD         Intel HD Graphics 620  No OS  1.86kg       575.00
3          4   Apple  MacBook Pro  Ultrabook    15.4  IPS Panel Retina Display 2880x1800        Intel Core i7 2.7GHz  16GB            512GB SSD            AMD Radeon Pro 455  macOS  1.83kg      2537.45
4          5   Apple  MacBook Pro  Ultrabook    13.3  IPS Panel Retina Display 2560x1600        Intel Core i5 3.1GHz   8GB            256GB SSD  Intel Iris Plus Graphics 650  macOS  1.37kg      1803.60

# all data from Company and Price_euros
data = {'Company': ['Apple', 'Apple', 'HP', 'Apple', 'Apple', 'Acer', 'Apple', 'Apple', 'Asus', 'Acer', 'HP', 'HP', 'Apple', 'Dell', 'Apple', 'Apple', 'Dell', 'Apple', 'Lenovo', 'Dell', 'Asus', 'Lenovo', 'HP', 'Dell', 'HP', 'Dell', 'Apple', 'Dell', 'Dell', 'HP', 'Chuwi', 'Asus', 'HP', 'Dell', 'Apple', 'Lenovo', 'Acer', 'Dell', 'HP', 'HP', 'Asus', 'Dell', 'Asus', 'Acer', 'Dell', 'Apple', 'Lenovo', 'Asus', 'Dell', 'Asus', 'Lenovo', 'Acer', 'HP', 'HP', 'Acer', 'Dell', 'HP', 'Asus', 'MSI', 'Asus', 'Dell', 'Dell', 'Lenovo', 'Asus', 'HP', 'Asus', 'HP', 'HP', 'Lenovo', 'Asus', 'Microsoft', 'Dell', 'Dell', 'MSI', 'Acer', 'Asus', 'Lenovo', 'Dell', 'Acer', 'HP', 'Dell', 'Apple', 'HP', 'Lenovo', 'Acer', 'Dell', 'HP', 'HP', 'Asus', 'Dell', 'Asus', 'Acer', 'HP', 'Dell', 'Asus', 'Acer', 'Dell', 'Dell', 'Asus', 'HP', 'HP', 'HP', 'Dell', 'HP', 'Microsoft', 'HP', 'Lenovo', 'Asus', 'MSI', 'Lenovo', 'Asus', 'Dell', 'Lenovo', 'HP', 'Dell', 'HP', 'HP', 'Dell', 'Asus', 'Asus', 'Acer', 'MSI', 'Lenovo', 'HP', 'Acer', 'HP', 'HP', 'Asus', 'Dell', 'HP', 'Dell', 'Dell', 'Acer', 'Acer', 'HP', 'HP', 'Lenovo', 'Asus', 'Lenovo', 'HP', 'Acer', 'Lenovo', 'Lenovo', 'Toshiba', 'HP', 'Asus', 'HP', 'Asus', 'MSI', 'Acer', 'Dell', 'Dell', 'Lenovo', 'MSI', 'HP', 'HP', 'Lenovo', 'Asus', 'Dell', 'Toshiba', 'Asus', 'Acer', 'Dell', 'Lenovo', 'Acer', 'MSI', 'Acer', 'Dell', 'Acer', 'HP', 'Huawei', 'HP', 'Lenovo', 'Toshiba', 'HP', 'Dell', 'Acer', 'MSI', 'Lenovo', 'HP', 'Dell', 'Dell', 'Lenovo', 'Toshiba', 'Xiaomi', 'Dell', 'Dell', 'Lenovo', 'Acer', 'Dell', 'Lenovo', 'Vero', 'Xiaomi', 'Lenovo', 'Dell', 'HP', 'Razer', 'HP', 'HP', 'HP', 'Dell', 'Lenovo', 'Acer', 'Lenovo', 'Dell', 'Lenovo', 'Dell', 'Dell', 'Dell', 'Lenovo', 'Acer', 'Asus', 'HP', 'Lenovo', 'Huawei', 'Dell', 'Lenovo', 'HP', 'Dell', 'Dell', 'Dell', 'Lenovo', 'Toshiba', 'HP', 'Dell', 'Acer', 'Dell', 'Asus', 'Asus', 'HP', 'Asus', 'HP', 'Lenovo', 'Dell', 'Acer', 'Dell', 'Acer', 'Asus', 'Asus', 'Acer', 'Lenovo', 'Asus', 'Asus', 'Dell', 'Lenovo', 'Dell', 'HP', 'Asus', 'HP', 'Apple', 'Dell', 'Asus', 'Asus', 'Lenovo', 'Acer', 'Dell', 'HP', 'HP', 'MSI', 'Lenovo', 'Dell', 'Lenovo', 'HP', 'Dell', 'Dell', 'Dell', 'Asus', 'Lenovo', 'HP', 'Lenovo', 'Apple', 'Asus', 'Dell', 'Lenovo', 'Toshiba', 'Dell', 'Dell', 'Acer', 'Lenovo', 'Lenovo', 'Lenovo', 'Dell', 'Lenovo', 'Lenovo', 'Acer', 'Acer', 'Lenovo', 'Asus', 'Lenovo', 'Lenovo', 'Acer', 'Asus', 'HP', 'Dell', 'Lenovo', 'Lenovo', 'Acer', 'Dell', 'Lenovo', 'Asus', 'Asus', 'Asus', 'Lenovo', 'Lenovo', 'Asus', 'Lenovo', 'HP', 'Toshiba', 'Lenovo', 'HP', 'Lenovo', 'Dell', 'MSI', 'Acer', 'Asus', 'Dell', 'HP', 'Lenovo', 'HP', 'Acer', 'HP', 'Lenovo', 'Asus', 'HP', 'Acer', 'Lenovo', 'Acer', 'Asus', 'HP', 'Dell', 'MSI', 'Toshiba', 'Asus', 'Lenovo', 'Asus', 'HP', 'Dell', 'HP', 'Asus', 'Dell', 'Dell', 'Lenovo', 'HP', 'Lenovo', 'Dell', 'Lenovo', 'HP', 'Dell', 'Asus', 'Dell', 'Dell', 'HP', 'MSI', 'HP', 'Toshiba', 'Dell', 'Lenovo', 'Dell', 'Dell', 'Dell', 'HP', 'Asus', 'Lenovo', 'HP', 'Lenovo', 'HP', 'Dell', 'Lenovo', 'Dell', 'HP', 'Asus', 'Acer', 'Asus', 'Lenovo', 'Dell', 'HP', 'Lenovo', 'Dell', 'Asus', 'Acer', 'HP', 'Lenovo', 'Asus', 'Lenovo', 'Asus', 'Lenovo', 'Lenovo', 'Dell', 'Dell', 'Lenovo', 'Asus', 'Asus', 'Acer', 'MSI', 'Dell', 'HP', 'Lenovo', 'Lenovo', 'Dell', 'Lenovo', 'Lenovo', 'Asus', 'Lenovo', 'Acer', 'MSI', 'Asus', 'Toshiba', 'Dell', 'Lenovo', 'Lenovo', 'Lenovo', 'Lenovo', 'HP', 'Acer', 'Asus', 'Dell', 'Dell', 'HP', 'Dell', 'Lenovo', 'Lenovo', 'Chuwi', 'HP', 'Asus', 'Dell', 'Dell', 'Dell', 'Dell', 'HP', 'Mediacom', 'Samsung', 'Lenovo', 'Lenovo', 'Lenovo', 'Lenovo', 'Asus', 'HP', 'Google', 'Lenovo', 'Asus', 'Lenovo', 'Dell', 'Lenovo', 'Lenovo', 'HP', 'Dell', 'Acer', 'Dell', 'MSI', 'Microsoft', 'HP', 'Dell', 'HP', 'Lenovo', 'Dell', 'Dell', 'Dell', 'Microsoft', 'Microsoft', 'HP', 'Acer', 'Acer', 'Asus', 'Lenovo', 'Lenovo', 'Asus', 'Acer', 'Dell', 'HP', 'Lenovo', 'HP', 'HP', 'Google', 'Dell', 'Asus', 'Dell', 'Dell', 'Lenovo', 'Dell', 'Toshiba', 'Dell', 'Dell', 'HP', 'Chuwi', 'Lenovo', 'Lenovo', 'Dell', 'Dell', 'Lenovo', 'Asus', 'Lenovo', 'Toshiba', 'Asus', 'Acer', 'Asus', 'Lenovo', 'Lenovo', 'HP', 'Lenovo', 'Lenovo', 'Asus', 'HP', 'Lenovo', 'Lenovo', 'Lenovo', 'Lenovo', 'Asus', 'Acer', 'HP', 'Lenovo', 'Dell', 'Acer', 'Dell', 'Dell', 'Xiaomi', 'Asus', 'HP', 'Asus', 'HP', 'Asus', 'Lenovo', 'HP', 'Dell', 'HP', 'Dell', 'Lenovo', 'Lenovo', 'Lenovo', 'Dell', 'Dell', 'Dell', 'Toshiba', 'Asus', 'Mediacom', 'Asus', 'Dell', 'Dell', 'HP', 'HP', 'Lenovo', 'Dell', 'Dell', 'HP', 'Acer', 'Asus', 'HP', 'Lenovo', 'Lenovo', 'HP', 'Lenovo', 'Lenovo', 'Dell', 'Dell', 'HP', 'HP', 'Asus', 'Mediacom', 'Lenovo', 'HP', 'Dell', 'Acer', 'Lenovo', 'HP', 'Lenovo', 'Asus', 'Dell', 'Dell', 'Fujitsu', 'Lenovo', 'Lenovo', 'HP', 'HP', 'HP', 'Lenovo', 'Lenovo', 'Mediacom', 'Toshiba', 'Lenovo', 'MSI', 'Dell', 'Mediacom', 'Dell', 'HP', 'Dell', 'Dell', 'MSI', 'HP', 'Lenovo', 'Lenovo', 'Asus', 'Asus', 'Lenovo', 'Dell', 'Samsung', 'Lenovo', 'Lenovo', 'Lenovo', 'Lenovo', 'Dell', 'Dell', 'HP', 'HP', 'Acer', 'MSI', 'Dell', 'MSI', 'Toshiba', 'Lenovo', 'Lenovo', 'Acer', 'Lenovo', 'Dell', 'Dell', 'Dell', 'Dell', 'Asus', 'Dell', 'HP', 'MSI', 'Acer', 'HP', 'Lenovo', 'Dell', 'Fujitsu', 'HP', 'Lenovo', 'Mediacom', 'Lenovo', 'Asus', 'Dell', 'Asus', 'Dell', 'Lenovo', 'Lenovo', 'Asus', 'Asus', 'Dell', 'Lenovo', 'Lenovo', 'Dell', 'Lenovo', 'HP', 'Lenovo', 'Asus', 'Acer', 'Lenovo', 'Acer', 'Razer', 'Toshiba', 'Lenovo', 'Asus', 'Acer', 'Dell', 'MSI', 'HP', 'Toshiba', 'Dell', 'Dell', 'Lenovo', 'Dell', 'Dell', 'Lenovo', 'Lenovo', 'HP', 'MSI', 'Toshiba', 'Dell', 'HP', 'Toshiba', 'Acer', 'Microsoft', 'Lenovo', 'Lenovo', 'Lenovo', 'HP', 'MSI', 'Asus', 'HP', 'LG', 'Acer', 'MSI', 'Asus', 'Dell', 'HP', 'Lenovo', 'Dell', 'HP', 'Dell', 'HP', 'Lenovo', 'Acer', 'Lenovo', 'HP', 'Lenovo', 'Toshiba', 'Acer', 'Lenovo', 'Asus', 'Toshiba', 'HP', 'Dell', 'Lenovo', 'Lenovo', 'Lenovo', 'Lenovo', 'Dell', 'Acer', 'Lenovo', 'Lenovo', 'HP', 'Lenovo', 'Dell', 'Dell', 'Asus', 'Dell', 'Lenovo', 'Dell', 'Lenovo', 'Mediacom', 'HP', 'Lenovo', 'HP', 'Lenovo', 'Dell', 'MSI', 'Lenovo', 'Dell', 'Dell', 'Dell', 'HP', 'Acer', 'Dell', 'HP', 'Acer', 'Lenovo', 'Lenovo', 'HP', 'Dell', 'MSI', 'Acer', 'Dell', 'Dell', 'Toshiba', 'Lenovo', 'Lenovo', 'Acer', 'Samsung', 'HP', 'Dell', 'HP', 'Lenovo', 'HP', 'Asus', 'Lenovo', 'Asus', 'Lenovo', 'HP', 'HP', 'Dell', 'Acer', 'Lenovo', 'Dell', 'Google', 'Asus', 'Dell', 'Acer', 'Asus', 'Dell', 'Samsung', 'Acer', 'Dell', 'Samsung', 'Toshiba', 'Dell', 'HP', 'Asus', 'Lenovo', 'Acer', 'Razer', 'Asus', 'Dell', 'Asus', 'Toshiba', 'Lenovo', 'Lenovo', 'MSI', 'MSI', 'Lenovo', 'Acer', 'Dell', 'Asus', 'Vero', 'Lenovo', 'Lenovo', 'Apple', 'Lenovo', 'Asus', 'Dell', 'Lenovo', 'Dell', 'HP', 'Asus', 'Dell', 'Dell', 'Dell', 'HP', 'Toshiba', 'HP', 'Dell', 'Lenovo', 'HP', 'MSI', 'Samsung', 'Dell', 'Dell', 'Lenovo', 'Razer', 'HP', 'Dell', 'Dell', 'Lenovo', 'Toshiba', 'Lenovo', 'MSI', 'Lenovo', 'Toshiba', 'Asus', 'Dell', 'Acer', 'Acer', 'Razer', 'Lenovo', 'Asus', 'Lenovo', 'Lenovo', 'Dell', 'Asus', 'Toshiba', 'Lenovo', 'Asus', 'Asus', 'Dell', 'HP', 'Dell', 'HP', 'Dell', 'HP', 'Asus', 'HP', 'HP', 'HP', 'Asus', 'Dell', 'Lenovo', 'Asus', 'Dell', 'Asus', 'HP', 'Dell', 'Lenovo', 'Lenovo', 'HP', 'Toshiba', 'Lenovo', 'Dell', 'HP', 'Toshiba', 'Lenovo', 'Acer', 'Dell', 'Lenovo', 'Lenovo', 'Toshiba', 'Lenovo', 'Samsung', 'Dell', 'Asus', 'Xiaomi', 'Dell', 'HP', 'HP', 'HP', 'Asus', 'Lenovo', 'Dell', 'HP', 'Dell', 'Asus', 'Acer', 'Lenovo', 'HP', 'HP', 'Samsung', 'Lenovo', 'MSI', 'Toshiba', 'Dell', 'HP', 'Dell', 'Dell', 'Dell', 'Asus', 'Dell', 'Lenovo', 'Lenovo', 'LG', 'HP', 'Acer', 'Lenovo', 'LG', 'Dell', 'HP', 'Lenovo', 'HP', 'Acer', 'Lenovo', 'HP', 'MSI', 'Dell', 'MSI', 'Dell', 'HP', 'HP', 'Toshiba', 'Lenovo', 'Dell', 'Lenovo', 'HP', 'Dell', 'HP', 'Lenovo', 'HP', 'HP', 'Lenovo', 'Toshiba', 'HP', 'Dell', 'MSI', 'Dell', 'Dell', 'HP', 'Asus', 'Acer', 'Toshiba', 'Lenovo', 'Lenovo', 'Dell', 'Lenovo', 'Dell', 'Acer', 'HP', 'Dell', 'Toshiba', 'Asus', 'Lenovo', 'Dell', 'Dell', 'HP', 'Dell', 'Acer', 'Toshiba', 'Lenovo', 'Acer', 'Toshiba', 'HP', 'Dell', 'Dell', 'HP', 'Dell', 'Lenovo', 'Dell', 'Dell', 'Dell', 'Toshiba', 'Asus', 'HP', 'Lenovo', 'Asus', 'HP', 'Asus', 'Dell', 'Toshiba', 'Lenovo', 'Fujitsu', 'Toshiba', 'Dell', 'HP', 'Lenovo', 'Dell', 'Dell', 'HP', 'HP', 'Lenovo', 'Lenovo', 'Dell', 'Asus', 'HP', 'Acer', 'Asus', 'HP', 'Acer', 'HP', 'Dell', 'HP', 'Toshiba', 'HP', 'HP', 'HP', 'HP', 'HP', 'Dell', 'HP', 'HP', 'HP', 'HP', 'Toshiba', 'HP', 'Lenovo', 'Toshiba', 'HP', 'Dell', 'Toshiba', 'HP', 'HP', 'Dell', 'HP', 'HP', 'HP', 'Dell', 'HP', 'HP', 'Acer', 'MSI', 'HP', 'HP', 'HP', 'HP', 'Toshiba', 'Dell', 'HP', 'Lenovo', 'Vero', 'Toshiba', 'Lenovo', 'HP', 'HP', 'HP', 'MSI', 'Lenovo', 'Asus', 'Lenovo', 'HP', 'Dell', 'HP', 'Dell', 'HP', 'HP', 'Acer', 'Dell', 'MSI', 'HP', 'Asus', 'Dell', 'Dell', 'MSI', 'Dell', 'Asus', 'Dell', 'Dell', 'Apple', 'Dell', 'HP', 'HP', 'HP', 'Lenovo', 'Lenovo', 'Lenovo', 'MSI', 'Lenovo', 'HP', 'Lenovo', 'Lenovo', 'Lenovo', 'HP', 'Dell', 'HP', 'HP', 'Lenovo', 'HP', 'Acer', 'Dell', 'HP', 'Asus', 'Dell', 'HP', 'Acer', 'Dell', 'MSI', 'HP', 'Asus', 'Dell', 'Dell', 'Acer', 'HP', 'Lenovo', 'Dell', 'MSI', 'Lenovo', 'HP', 'Asus', 'HP', 'Dell', 'Lenovo', 'HP', 'Lenovo', 'Dell', 'Lenovo', 'Razer', 'Toshiba', 'Asus', 'Vero', 'HP', 'HP', 'Dell', 'Asus', 'Lenovo', 'Lenovo', 'HP', 'Lenovo', 'HP', 'HP', 'Lenovo', 'Asus', 'HP', 'Acer', 'Lenovo', 'HP', 'Dell', 'MSI', 'HP', 'Lenovo', 'MSI', 'HP', 'HP', 'HP', 'HP', 'HP', 'Dell', 'HP', 'Lenovo', 'Lenovo', 'HP', 'Lenovo', 'Dell', 'Dell', 'HP', 'MSI', 'Lenovo', 'Lenovo', 'HP', 'Lenovo', 'MSI', 'HP', 'Lenovo', 'HP', 'Dell', 'Lenovo', 'Lenovo', 'HP', 'MSI', 'HP', 'HP', 'Asus', 'Lenovo', 'Lenovo', 'Asus', 'Lenovo', 'Lenovo', 'MSI', 'HP', 'Lenovo', 'Lenovo', 'Dell', 'Acer', 'HP', 'Asus', 'Dell', 'Acer', 'Dell', 'Acer', 'Lenovo', 'Samsung', 'HP', 'Apple', 'Dell', 'HP', 'Lenovo', 'Asus', 'Acer', 'MSI', 'Dell', 'Lenovo', 'Dell', 'Dell', 'Asus', 'Dell', 'HP', 'Lenovo', 'Acer', 'Asus', 'Apple', 'Asus', 'MSI', 'Dell', 'Asus', 'Acer', 'Acer', 'Lenovo', 'Lenovo', 'Acer', 'Lenovo', 'MSI', 'HP', 'Dell', 'Dell', 'Asus', 'Dell', 'Dell', 'Lenovo', 'MSI', 'Lenovo', 'Razer', 'Dell', 'MSI', 'Apple', 'HP', 'HP', 'Dell', 'MSI', 'Lenovo', 'Lenovo', 'Asus', 'Acer', 'Dell', 'HP', 'Asus', 'Dell', 'Asus', 'Lenovo', 'Dell', 'Dell', 'HP', 'Lenovo', 'Lenovo', 'Dell', 'Asus', 'Asus', 'Dell', 'Lenovo', 'MSI', 'Lenovo', 'Asus', 'Dell', 'Acer', 'Dell', 'Lenovo', 'HP', 'Dell', 'HP', 'Asus', 'Lenovo', 'Lenovo', 'Lenovo', 'HP', 'Asus', 'Asus', 'Dell', 'Acer', 'Dell', 'Lenovo', 'HP', 'Dell', 'HP', 'Asus', 'Lenovo', 'Lenovo', 'Lenovo', 'HP', 'Asus', 'Asus', 'Dell', 'Acer', 'Dell', 'Lenovo', 'HP', 'Dell', 'HP', 'Asus', 'Lenovo', 'Lenovo', 'Lenovo', 'HP', 'Asus'], 'Price_euros': [1339.69, 898.94, 575.0, 2537.45, 1803.6, 400.0, 2139.97, 1158.7, 1495.0, 770.0, 393.9, 344.99, 2439.97, 498.9, 1262.4, 1518.55, 745.0, 2858.0, 499.0, 979.0, 191.9, 999.0, 258.0, 819.0, 659.0, 418.64, 1099.0, 800.0, 1298.0, 896.0, 244.99, 199.0, 439.0, 1869.0, 998.0, 249.0, 367.0, 979.0, 488.69, 879.0, 389.0, 1499.0, 522.99, 682.0, 999.0, 1419.0, 369.0, 1299.0, 639.0, 466.0, 319.0, 841.0, 398.49, 1103.0, 384.0, 767.8, 439.0, 586.19, 2449.0, 415.0, 1299.0, 879.0, 599.0, 941.0, 690.0, 1983.0, 438.69, 229.0, 549.0, 949.0, 1089.0, 955.0, 870.0, 1095.0, 389.0, 949.0, 519.0, 855.0, 530.0, 977.0, 1096.16, 1510.0, 860.0, 399.0, 395.0, 1349.0, 699.0, 598.99, 1449.0, 1649.0, 699.0, 689.0, 1197.0, 1195.0, 1049.0, 847.0, 599.9, 485.0, 577.0, 1249.0, 719.0, 349.0, 647.0, 1119.0, 1340.0, 659.0, 414.9, 1193.0, 1299.0, 1480.0, 1262.0, 1379.0, 1399.0, 722.0, 1629.0, 1398.99, 1084.0, 1130.33, 564.0, 1118.0, 479.0, 2241.5, 629.0, 1271.0, 451.0, 259.0, 812.0, 277.99, 1396.0, 928.0, 638.99, 449.0, 884.0, 572.0, 598.0, 988.0, 252.36, 938.0, 499.0, 699.0, 655.0, 1116.02, 869.0, 602.0, 369.0, 1099.0, 2014.0, 344.0, 2029.0, 447.0, 1249.26, 899.0, 498.0, 1890.0, 1082.0, 619.0, 629.0, 1315.0, 1049.0, 447.0, 403.0, 805.0, 728.0, 1079.0, 348.0, 1799.0, 363.51, 1060.49, 854.0, 754.0, 1349.0, 699.0, 309.0, 489.0, 923.0, 459.0, 449.0, 2799.0, 813.0, 1499.0, 1049.0, 1399.0, 1849.0, 793.0, 1199.0, 1549.0, 2397.0, 779.0, 989.0, 1085.0, 2824.0, 260.0, 999.9, 698.0, 839.0, 914.0, 6099.0, 959.0, 1379.0, 1045.0, 1845.0, 493.0, 742.0, 1749.0, 3055.0, 1398.0, 439.0, 1949.0, 1449.0, 597.0, 779.0, 1407.0, 349.0, 549.0, 1499.0, 931.88, 589.0, 1031.0, 1149.0, 1279.0, 677.35, 899.0, 1363.0, 794.0, 2456.34, 832.0, 859.01, 769.0, 891.0, 1269.0, 398.99, 330.0, 1499.0, 859.0, 689.0, 899.0, 390.0, 575.0, 3890.0, 846.0, 589.0, 1145.0, 889.0, 879.0, 1079.0, 985.0, 559.0, 2999.0, 675.0, 2040.0, 819.0, 1799.0, 469.0, 1849.0, 702.0, 949.0, 445.9, 1059.0, 2499.0, 1699.0, 1142.0, 444.0, 722.0, 657.0, 565.0, 799.0, 1499.0, 467.0, 1018.0, 880.0, 1958.9, 1549.0, 735.07, 2499.0, 812.0, 713.07, 1099.0, 745.0, 489.0, 849.0, 859.0, 428.0, 829.0, 579.0, 951.0, 659.0, 1097.0, 977.0, 1179.0, 659.01, 199.0, 1187.0, 489.0, 1829.0, 739.0, 1299.0, 979.0, 2884.86, 499.0, 1468.0, 509.0, 2122.0, 649.0, 549.0, 1265.0, 359.99, 1975.0, 1043.0, 819.0, 469.0, 999.0, 2499.0, 2099.0, 469.0, 275.0, 844.0, 2449.0, 459.9, 980.0, 485.0, 1292.0, 589.0, 1094.0, 902.0, 659.0, 292.0, 549.0, 1049.9, 1335.0, 2639.0, 1199.0, 943.0, 1334.0, 449.0, 999.0, 1268.0, 1049.0, 1144.0, 274.99, 1142.75, 274.9, 899.0, 716.0, 2099.0, 1579.0, 1129.0, 279.0, 1607.96, 375.0, 663.0, 2027.42, 1304.0, 1409.0, 1738.27, 1403.0, 970.9, 321.99, 999.0, 557.37, 1427.0, 439.0, 945.0, 719.0, 639.0, 499.0, 389.0, 1085.0, 809.0, 899.0, 1750.0, 1099.0, 426.0, 2199.0, 489.0, 869.01, 488.99, 553.0, 309.0, 286.0, 846.0, 1191.0, 403.5, 1655.0, 1099.0, 1748.9, 2282.0, 549.0, 1369.0, 2135.0, 2509.0, 1039.0, 1591.0, 693.99, 1349.0, 778.87, 499.0, 1229.56, 938.0, 2712.0, 2625.0, 306.0, 1529.0, 1144.5, 879.0, 2249.0, 1873.0, 1747.0, 1680.0, 409.0, 304.45, 1925.0, 1943.0, 469.0, 789.01, 928.0, 598.9, 689.0, 1500.0, 539.95, 1215.38, 1899.0, 449.0, 1427.0, 597.0, 2799.0, 1159.0, 1142.4, 1099.0, 1999.0, 299.0, 269.0, 1010.0, 599.0, 2445.0, 2449.0, 1695.0, 347.0, 2199.0, 2382.0, 559.0, 519.0, 749.0, 1429.0, 349.0, 1099.0, 1179.0, 441.8, 1993.0, 1027.74, 2589.0, 589.0, 1975.0, 1534.0, 1345.0, 979.0, 479.0, 2046.0, 989.0, 1799.0, 639.9, 544.0, 435.0, 749.0, 799.0, 2090.0, 304.0, 469.0, 759.0, 1699.0, 1858.0, 1999.0, 1154.0, 1275.0, 1841.85, 1299.0, 740.0, 2408.0, 1364.0, 675.0, 1672.0, 1262.0, 586.6, 726.0, 248.9, 565.0, 1049.0, 2338.0, 1899.0, 1798.0, 1950.0, 1011.99, 2799.0, 1350.0, 579.0, 1269.0, 1099.0, 898.9, 1749.0, 949.0, 911.0, 340.0, 618.99, 1599.0, 299.0, 265.0, 949.0, 1224.0, 613.0, 1323.0, 1149.0, 899.0, 639.0, 836.0, 1219.24, 1399.95, 245.0, 521.47, 2968.0, 889.0, 1504.0, 1399.0, 1399.0, 1279.73, 689.0, 889.0, 1340.0, 799.0, 459.0, 585.0, 1377.0, 3012.77, 860.0, 1299.0, 369.0, 1649.0, 1369.0, 797.41, 398.99, 1799.0, 859.0, 1399.0, 735.87, 1145.0, 798.0, 349.0, 705.5, 785.0, 462.35, 397.0, 1729.0, 499.0, 1116.99, 2699.0, 544.15, 1280.0, 224.0, 255.0, 949.0, 568.9, 617.9, 349.0, 630.0, 1965.0, 2999.0, 839.0, 1599.0, 959.0, 739.0, 344.0, 990.0, 1860.99, 389.0, 649.0, 830.0, 685.0, 249.0, 1865.0, 2663.0, 2729.0, 749.01, 389.0, 1008.52, 719.0, 1537.39, 295.0, 2349.0, 1498.0, 1673.0, 609.0, 1770.0, 739.0, 949.0, 603.0, 1699.0, 529.0, 459.0, 2025.0, 1474.0, 1670.0, 1763.0, 1219.0, 668.48, 329.0, 2199.0, 465.0, 2299.0, 1399.0, 564.0, 1299.0, 349.0, 4899.0, 879.01, 443.9, 359.0, 869.0, 1168.0, 569.0, 1389.0, 2267.86, 379.0, 1124.0, 1465.0, 776.0, 799.0, 932.0, 899.0, 239.0, 468.0, 639.01, 1820.0, 1900.0, 1479.0, 829.0, 579.0, 399.0, 906.62, 1869.0, 249.0, 1757.42, 2399.0, 1109.0, 520.9, 2450.0, 1169.0, 450.0, 274.0, 919.0, 2599.0, 1213.0, 1584.0, 2799.0, 709.0, 1449.9, 1191.8, 364.9, 1064.0, 919.0, 1135.0, 1196.0, 3147.37, 1229.0, 419.0, 535.0, 539.0, 1486.77, 498.0, 955.0, 745.0, 1258.0, 412.0, 1867.85, 817.95, 1034.0, 349.0, 699.0, 1294.0, 1135.0, 495.0, 2299.0, 1299.0, 997.9, 419.0, 2051.0, 699.0, 1499.0, 2813.75, 612.61, 545.67, 569.0, 318.0, 375.0, 699.0, 1907.99, 2590.0, 973.0, 269.0, 1749.0, 669.0, 1877.0, 689.0, 819.0, 399.0, 429.0, 621.45, 450.0, 795.0, 999.0, 1855.0, 1191.0, 655.01, 1249.0, 1089.0, 726.0, 298.0, 1426.66, 857.07, 1179.0, 298.0, 265.0, 1200.0, 1686.64, 836.6, 1499.0, 3659.4, 1348.48, 489.9, 719.0, 649.0, 589.52, 489.0, 1935.0, 649.0, 650.0, 559.0, 960.0, 779.0, 2419.0, 659.0, 2094.48, 410.8, 1207.0, 665.0, 1535.0, 999.0, 3299.0, 330.0, 1649.0, 539.0, 1126.71, 4389.0, 475.0, 1900.0, 579.0, 1096.0, 849.9, 1199.0, 1099.0, 1561.0, 2868.99, 599.0, 1048.0, 1859.0, 1559.0, 1129.0, 849.0, 655.0, 470.34, 1099.0, 1599.0, 298.0, 1181.27, 1799.0, 1020.0, 1099.0, 1244.0, 839.0, 2370.0, 636.0, 2899.0, 581.9, 3588.8, 2350.0, 1764.0, 329.0, 2299.0, 1891.0, 1089.0, 999.0, 2299.0, 985.0, 1339.0, 202.9, 1970.0, 959.0, 1165.0, 2330.0, 299.0, 810.0, 1349.0, 739.0, 2064.9, 1099.0, 1499.0, 1749.0, 744.0, 1389.0, 780.0, 629.0, 1679.0, 609.0, 1749.0, 2415.0, 1499.0, 961.0, 789.81, 1859.0, 1799.0, 385.0, 2505.02, 755.0, 489.9, 1090.0, 2499.0, 1199.0, 1875.0, 499.0, 1358.0, 585.0, 355.0, 619.0, 5499.0, 2099.0, 519.0, 1186.0, 1650.0, 2774.63, 2419.0, 669.0, 325.0, 590.0, 1799.0, 3072.89, 910.0, 713.99, 1870.0, 739.0, 615.0, 1026.0, 2277.0, 1468.0, 299.0, 1899.0, 865.0, 1903.0, 787.0, 945.0, 449.0, 2559.0, 649.0, 469.0, 850.66, 1349.0, 1285.0, 1017.0, 2240.0, 910.0, 1095.0, 1950.0, 902.0, 1778.0, 1055.0, 479.0, 1388.0, 735.0, 1849.0, 1690.0, 398.99, 935.0, 912.5, 839.0, 1700.0, 684.8, 348.0, 669.0, 369.0, 1799.0, 455.7, 1369.9, 297.0, 379.0, 1265.0, 1399.0, 1699.0, 1799.0, 2649.0, 1475.0, 929.0, 900.0, 614.0, 935.0, 2013.1, 1279.0, 1649.0, 2049.0, 1962.99, 2099.0, 1483.0, 359.0, 789.0, 1899.0, 1205.0, 3100.0, 789.0, 1018.99, 499.0, 881.0, 960.0, 1599.0, 1349.0, 1119.91, 684.99, 1296.99, 1149.0, 1975.0, 1825.0, 729.9, 1650.0, 1165.0, 708.06, 1149.0, 309.0, 1579.0, 288.9, 1799.0, 1105.0, 1669.0, 558.6, 1199.0, 1639.0, 2758.0, 1399.0, 530.0, 619.0, 1119.0, 1299.0, 999.0, 1472.2, 685.0, 659.0, 349.0, 2249.0, 1775.0, 1460.0, 1159.0, 1488.99, 3154.0, 1899.0, 775.0, 1268.0, 389.0, 1535.0, 1760.0, 1009.0, 1790.0, 846.5, 465.62, 825.0, 685.0, 3149.0, 695.0, 1899.0, 1962.98, 2800.0, 1180.0, 2049.9, 979.0, 1002.0, 1799.0, 579.0, 1749.0, 1299.0, 1195.0, 549.0, 649.0, 915.0, 599.0, 806.0, 1189.0, 749.0, 1119.0, 1908.0, 499.0, 270.62, 1349.0, 889.0, 1150.0, 1349.0, 380.0, 1799.0, 2089.0, 1260.0, 1189.0, 547.0, 779.0, 1195.0, 1099.99, 1205.0, 1449.0, 1049.26, 684.0, 949.0, 1539.0, 1590.0, 1887.21, 800.0, 1210.0, 769.99, 2968.0, 1490.0, 2229.0, 795.99, 1590.0, 1149.0, 1185.43, 1046.44, 1559.0, 1189.0, 1060.0, 1624.0, 1080.0, 973.0, 409.0, 1191.8, 1195.0, 1228.99, 1349.0, 742.0, 1725.0, 1062.95, 1010.51, 847.0, 210.8, 1425.0, 1049.6, 1000.0, 2103.34, 1469.0, 1545.64, 2289.99, 287.9, 2620.0, 979.0, 1094.0, 979.0, 2254.0, 705.15, 499.0, 449.0, 1299.0, 1819.0, 1070.0, 998.0, 559.0, 989.99, 1929.0, 1458.0, 3975.0, 798.01, 1329.0, 1300.0, 481.98, 1199.0, 1199.0, 1090.0, 1713.49, 659.0, 977.0, 2499.0, 540.0, 940.0, 1399.0, 3240.0, 646.27, 2049.0, 750.0, 1030.99, 1495.0, 1199.0, 615.0, 387.0, 393.49, 345.99, 1599.0, 818.35, 1599.0, 799.0, 638.8, 1599.0, 500.0, 2299.0, 1135.15, 1166.97, 209.0, 2899.0, 1199.0, 1413.1, 1511.19, 867.0, 398.0, 1339.0, 1699.0, 769.15, 429.0, 1969.0, 549.0, 1379.0, 2749.99, 1029.0, 2226.0, 1312.49, 196.0, 1690.0, 1513.0, 523.63, 435.0, 1669.0, 479.0, 1895.0, 989.0, 1129.0, 629.0, 2050.38, 278.0, 752.0, 616.0, 1099.0, 3949.4, 784.0, 2399.0, 2171.72, 2440.0, 1142.8, 1629.0, 2229.0, 1799.0, 1899.0, 2296.95, 1009.9, 1579.0, 2339.0, 339.0, 297.0, 599.0, 1199.0, 2250.68, 478.89, 1492.8, 2299.0, 788.49, 2041.0, 1499.0, 1769.0, 899.0, 459.0, 476.99, 1498.0, 1390.0, 468.0, 249.0, 839.0, 679.0, 1159.0, 369.0, 398.0, 709.0, 769.0, 825.0, 1305.0, 2153.37, 650.0, 1637.0, 831.0, 895.01, 333.0, 799.0, 909.0, 1179.0, 691.0, 1099.0, 2599.0, 819.0, 659.0, 485.0, 1163.0, 1199.0, 1327.0, 368.0, 2150.0, 272.0, 2048.9, 499.0, 629.0, 1285.0, 2680.0, 1169.0, 889.0, 579.0, 299.0, 629.0, 2449.0, 1279.0, 1749.0, 1948.99, 999.0, 1949.0, 174.0, 598.0, 539.0, 1272.0, 1149.0, 1529.0, 1476.11, 529.0, 1713.37, 509.0, 309.0, 1477.0, 521.86, 1029.0, 1149.0, 1650.0, 3499.0, 469.01, 1598.0, 959.0, 478.0, 2198.19, 737.0, 1169.0, 1499.0, 597.57, 1280.0, 361.8, 1799.0, 1099.99, 1600.0, 875.0, 2325.0, 573.0, 1813.0, 324.0, 399.0, 569.0, 1072.0, 443.99, 339.0, 1900.0, 490.0, 895.0, 1229.0, 833.01, 729.0, 459.0, 289.0, 379.0, 899.0, 549.99, 805.99, 209.0, 720.32, 638.0, 1499.0, 229.0, 764.0, 369.0, 729.0, 459.0, 289.0, 379.0, 899.0, 549.99, 805.99, 209.0, 720.32, 638.0, 1499.0, 229.0, 764.0, 369.0, 729.0, 459.0, 289.0, 379.0, 899.0, 549.99, 805.99, 209.0, 720.32, 638.0, 1499.0, 229.0, 764.0, 369.0]}

df = pd.DataFrame(data)

Solution

    • Use seaborn.boxplot
      • seaborn is a high-level API for matplotlib
    • Solved with pandas v1.2.4 and seaborn v0.11.1

    Import and Load Data

    import pandas as pd
    import seaborn as sns
    
    # load data
    dftrain = pd.read_csv('laptop_price.csv', encoding='latin-1')
    

    Plot Ordered Alphabetically

    # to sort alphabetically by company
    dftrain.Company = pd.Categorical(dftrain.Company, categories=sorted(dftrain.Company.unique()), ordered=True)
    
    # plot
    plt.figure(figsize=(8, 6))
    sns.boxplot(data=dftrain, x='Price_euros', y='Company')
    

    enter image description here

    Plot Ordered by the mean

    # get the index for the mean of each company
    mean_index = dftrain.groupby('Company').Price_euros.mean().sort_values().index
    
    # plot using order
    plt.figure(figsize=(8, 6))
    sns.boxplot(data=dftrain, x='Price_euros', y='Company', order=mean_index)
    

    enter image description here