Changing the style of scatter plot points

Let's continue exploring Seaborn's mpg dataset by looking at the relationship between how fast a car can accelerate ("acceleration") and its fuel efficiency ("mpg"). Do these properties vary by country of origin ("origin")?

Note that the "acceleration" variable is the time to accelerate from 0 to 60 miles per hour, in seconds. Higher values indicate slower acceleration.

# Import Matplotlib and Seaborn
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
url = 'https://assets.datacamp.com/production/repositories/3996/datasets/e0b285b89bdbfbbe8d81123e64727ff150d544e0/mpg.csv'
mpg = pd.read_csv(url)
print(mpg)
mpg cylinders displacement horsepower weight acceleration \
0 18.0 8 307.0 130.0 3504 12.0
1 15.0 8 350.0 165.0 3693 11.5
2 18.0 8 318.0 150.0 3436 11.0
3 16.0 8 304.0 150.0 3433 12.0
4 17.0 8 302.0 140.0 3449 10.5
5 15.0 8 429.0 198.0 4341 10.0
6 14.0 8 454.0 220.0 4354 9.0
7 14.0 8 440.0 215.0 4312 8.5
8 14.0 8 455.0 225.0 4425 10.0
9 15.0 8 390.0 190.0 3850 8.5
10 15.0 8 383.0 170.0 3563 10.0
11 14.0 8 340.0 160.0 3609 8.0
12 15.0 8 400.0 150.0 3761 9.5
13 14.0 8 455.0 225.0 3086 10.0
14 24.0 4 113.0 95.0 2372 15.0
15 22.0 6 198.0 95.0 2833 15.5
16 18.0 6 199.0 97.0 2774 15.5
17 21.0 6 200.0 85.0 2587 16.0
18 27.0 4 97.0 88.0 2130 14.5
19 26.0 4 97.0 46.0 1835 20.5
20 25.0 4 110.0 87.0 2672 17.5
21 24.0 4 107.0 90.0 2430 14.5
22 25.0 4 104.0 95.0 2375 17.5
23 26.0 4 121.0 113.0 2234 12.5
24 21.0 6 199.0 90.0 2648 15.0
25 10.0 8 360.0 215.0 4615 14.0
26 10.0 8 307.0 200.0 4376 15.0
27 11.0 8 318.0 210.0 4382 13.5
28 9.0 8 304.0 193.0 4732 18.5
29 27.0 4 97.0 88.0 2130 14.5
.. ... ... ... ... ... ...
368 27.0 4 112.0 88.0 2640 18.6
369 34.0 4 112.0 88.0 2395 18.0
370 31.0 4 112.0 85.0 2575 16.2
371 29.0 4 135.0 84.0 2525 16.0
372 27.0 4 151.0 90.0 2735 18.0
373 24.0 4 140.0 92.0 2865 16.4
374 23.0 4 151.0 NaN 3035 20.5
375 36.0 4 105.0 74.0 1980 15.3
376 37.0 4 91.0 68.0 2025 18.2
377 31.0 4 91.0 68.0 1970 17.6
378 38.0 4 105.0 63.0 2125 14.7
379 36.0 4 98.0 70.0 2125 17.3
380 36.0 4 120.0 88.0 2160 14.5
381 36.0 4 107.0 75.0 2205 14.5
382 34.0 4 108.0 70.0 2245 16.9
383 38.0 4 91.0 67.0 1965 15.0
384 32.0 4 91.0 67.0 1965 15.7
385 38.0 4 91.0 67.0 1995 16.2
386 25.0 6 181.0 110.0 2945 16.4
387 38.0 6 262.0 85.0 3015 17.0
388 26.0 4 156.0 92.0 2585 14.5
389 22.0 6 232.0 112.0 2835 14.7
390 32.0 4 144.0 96.0 2665 13.9
391 36.0 4 135.0 84.0 2370 13.0
392 27.0 4 151.0 90.0 2950 17.3
393 27.0 4 140.0 86.0 2790 15.6
394 44.0 4 97.0 52.0 2130 24.6
395 32.0 4 135.0 84.0 2295 11.6
396 28.0 4 120.0 79.0 2625 18.6
397 31.0 4 119.0 82.0 2720 19.4
model_year origin name
0 70 usa chevrolet chevelle malibu
1 70 usa buick skylark 320
2 70 usa plymouth satellite
3 70 usa amc rebel sst
4 70 usa ford torino
5 70 usa ford galaxie 500
6 70 usa chevrolet impala
7 70 usa plymouth fury iii
8 70 usa pontiac catalina
9 70 usa amc ambassador dpl
10 70 usa dodge challenger se
11 70 usa plymouth 'cuda 340
12 70 usa chevrolet monte carlo
13 70 usa buick estate wagon (sw)
14 70 japan toyota corona mark ii
15 70 usa plymouth duster
16 70 usa amc hornet
17 70 usa ford maverick
18 70 japan datsun pl510
19 70 europe volkswagen 1131 deluxe sedan
20 70 europe peugeot 504
21 70 europe audi 100 ls
22 70 europe saab 99e
23 70 europe bmw 2002
24 70 usa amc gremlin
25 70 usa ford f250
26 70 usa chevy c20
27 70 usa dodge d200
28 70 usa hi 1200d
29 71 japan datsun pl510
.. ... ... ...
368 82 usa chevrolet cavalier wagon
369 82 usa chevrolet cavalier 2-door
370 82 usa pontiac j2000 se hatchback
371 82 usa dodge aries se
372 82 usa pontiac phoenix
373 82 usa ford fairmont futura
374 82 usa amc concord dl
375 82 europe volkswagen rabbit l
376 82 japan mazda glc custom l
377 82 japan mazda glc custom
378 82 usa plymouth horizon miser
379 82 usa mercury lynx l
380 82 japan nissan stanza xe
381 82 japan honda accord
382 82 japan toyota corolla
383 82 japan honda civic
384 82 japan honda civic (auto)
385 82 japan datsun 310 gx
386 82 usa buick century limited
387 82 usa oldsmobile cutlass ciera (diesel)
388 82 usa chrysler lebaron medallion
389 82 usa ford granada l
390 82 japan toyota celica gt
391 82 usa dodge charger 2.2
392 82 usa chevrolet camaro
393 82 usa ford mustang gl
394 82 europe vw pickup
395 82 usa dodge rampage
396 82 usa ford ranger
397 82 usa chevy s-10
[398 rows x 9 columns]
# Import Matplotlib and Seaborn
import matplotlib.pyplot as plt
import seaborn as sns
# Create a scatter plot of acceleration vs. mpg
sns.relplot(x='acceleration', y='mpg',
data=mpg,
kind='scatter',
style='origin',
hue='origin')
# Show plot
plt.show()

All the contents are from DataCamp

Changing the size of scatter plot points

In this exercise, we'll explore Seaborn's mpg dataset, which contains one row per car model and includes information such as the year the car was made, the number of miles per gallon ("M.P.G.") it achieves, the power of its engine (measured in "horsepower"), and its country of origin.

What is the relationship between the power of a car's engine ("horsepower") and its fuel efficiency ("mpg")? And how does this relationship vary by the number of cylinders ("cylinders") the car has? Let's find out.

Let's continue to use relplot() instead of scatterplot() since it offers more flexibility.

# Import Matplotlib and Seaborn
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
url = 'https://assets.datacamp.com/production/repositories/3996/datasets/e0b285b89bdbfbbe8d81123e64727ff150d544e0/mpg.csv'
mpg = pd.read_csv(url)
print(mpg)
mpg cylinders displacement horsepower weight acceleration \
0 18.0 8 307.0 130.0 3504 12.0
1 15.0 8 350.0 165.0 3693 11.5
2 18.0 8 318.0 150.0 3436 11.0
3 16.0 8 304.0 150.0 3433 12.0
4 17.0 8 302.0 140.0 3449 10.5
5 15.0 8 429.0 198.0 4341 10.0
6 14.0 8 454.0 220.0 4354 9.0
7 14.0 8 440.0 215.0 4312 8.5
8 14.0 8 455.0 225.0 4425 10.0
9 15.0 8 390.0 190.0 3850 8.5
10 15.0 8 383.0 170.0 3563 10.0
11 14.0 8 340.0 160.0 3609 8.0
12 15.0 8 400.0 150.0 3761 9.5
13 14.0 8 455.0 225.0 3086 10.0
14 24.0 4 113.0 95.0 2372 15.0
15 22.0 6 198.0 95.0 2833 15.5
16 18.0 6 199.0 97.0 2774 15.5
17 21.0 6 200.0 85.0 2587 16.0
18 27.0 4 97.0 88.0 2130 14.5
19 26.0 4 97.0 46.0 1835 20.5
20 25.0 4 110.0 87.0 2672 17.5
21 24.0 4 107.0 90.0 2430 14.5
22 25.0 4 104.0 95.0 2375 17.5
23 26.0 4 121.0 113.0 2234 12.5
24 21.0 6 199.0 90.0 2648 15.0
25 10.0 8 360.0 215.0 4615 14.0
26 10.0 8 307.0 200.0 4376 15.0
27 11.0 8 318.0 210.0 4382 13.5
28 9.0 8 304.0 193.0 4732 18.5
29 27.0 4 97.0 88.0 2130 14.5
.. ... ... ... ... ... ...
368 27.0 4 112.0 88.0 2640 18.6
369 34.0 4 112.0 88.0 2395 18.0
370 31.0 4 112.0 85.0 2575 16.2
371 29.0 4 135.0 84.0 2525 16.0
372 27.0 4 151.0 90.0 2735 18.0
373 24.0 4 140.0 92.0 2865 16.4
374 23.0 4 151.0 NaN 3035 20.5
375 36.0 4 105.0 74.0 1980 15.3
376 37.0 4 91.0 68.0 2025 18.2
377 31.0 4 91.0 68.0 1970 17.6
378 38.0 4 105.0 63.0 2125 14.7
379 36.0 4 98.0 70.0 2125 17.3
380 36.0 4 120.0 88.0 2160 14.5
381 36.0 4 107.0 75.0 2205 14.5
382 34.0 4 108.0 70.0 2245 16.9
383 38.0 4 91.0 67.0 1965 15.0
384 32.0 4 91.0 67.0 1965 15.7
385 38.0 4 91.0 67.0 1995 16.2
386 25.0 6 181.0 110.0 2945 16.4
387 38.0 6 262.0 85.0 3015 17.0
388 26.0 4 156.0 92.0 2585 14.5
389 22.0 6 232.0 112.0 2835 14.7
390 32.0 4 144.0 96.0 2665 13.9
391 36.0 4 135.0 84.0 2370 13.0
392 27.0 4 151.0 90.0 2950 17.3
393 27.0 4 140.0 86.0 2790 15.6
394 44.0 4 97.0 52.0 2130 24.6
395 32.0 4 135.0 84.0 2295 11.6
396 28.0 4 120.0 79.0 2625 18.6
397 31.0 4 119.0 82.0 2720 19.4
model_year origin name
0 70 usa chevrolet chevelle malibu
1 70 usa buick skylark 320
2 70 usa plymouth satellite
3 70 usa amc rebel sst
4 70 usa ford torino
5 70 usa ford galaxie 500
6 70 usa chevrolet impala
7 70 usa plymouth fury iii
8 70 usa pontiac catalina
9 70 usa amc ambassador dpl
10 70 usa dodge challenger se
11 70 usa plymouth 'cuda 340
12 70 usa chevrolet monte carlo
13 70 usa buick estate wagon (sw)
14 70 japan toyota corona mark ii
15 70 usa plymouth duster
16 70 usa amc hornet
17 70 usa ford maverick
18 70 japan datsun pl510
19 70 europe volkswagen 1131 deluxe sedan
20 70 europe peugeot 504
21 70 europe audi 100 ls
22 70 europe saab 99e
23 70 europe bmw 2002
24 70 usa amc gremlin
25 70 usa ford f250
26 70 usa chevy c20
27 70 usa dodge d200
28 70 usa hi 1200d
29 71 japan datsun pl510
.. ... ... ...
368 82 usa chevrolet cavalier wagon
369 82 usa chevrolet cavalier 2-door
370 82 usa pontiac j2000 se hatchback
371 82 usa dodge aries se
372 82 usa pontiac phoenix
373 82 usa ford fairmont futura
374 82 usa amc concord dl
375 82 europe volkswagen rabbit l
376 82 japan mazda glc custom l
377 82 japan mazda glc custom
378 82 usa plymouth horizon miser
379 82 usa mercury lynx l
380 82 japan nissan stanza xe
381 82 japan honda accord
382 82 japan toyota corolla
383 82 japan honda civic
384 82 japan honda civic (auto)
385 82 japan datsun 310 gx
386 82 usa buick century limited
387 82 usa oldsmobile cutlass ciera (diesel)
388 82 usa chrysler lebaron medallion
389 82 usa ford granada l
390 82 japan toyota celica gt
391 82 usa dodge charger 2.2
392 82 usa chevrolet camaro
393 82 usa ford mustang gl
394 82 europe vw pickup
395 82 usa dodge rampage
396 82 usa ford ranger
397 82 usa chevy s-10
[398 rows x 9 columns]
# Import Matplotlib and Seaborn
import matplotlib.pyplot as plt
import seaborn as sns
# Create scatter plot of horsepower vs. mpg
sns.relplot(x="horsepower", y="mpg",
data=mpg,
kind="scatter",
size="cylinders", # size
hue='cylinders') # color
# Show plot
plt.show()

 

All the contents are from DataCamp

 

Learn R, Python & Data Science Online

 

www.datacamp.com

 

Creating two-factor subplots

Let's continue looking at the student_data dataset of students in secondary school. Here, we want to answer the following question: does a student's first semester grade ("G1") tend to correlate with their final grade ("G3")?

There are many aspects of a student's life that could result in a higher or lower final grade in the class. For example, some students receive extra educational support from their school ("schoolsup") or from their family ("famsup"), which could result in higher grades. Let's try to control for these two factors by creating subplots based on whether the student received extra educational support from their school or family.

Seaborn has been imported as sns and matplotlib.pyplot has been imported as plt.

# Import Matplotlib and Seaborn
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
url = 'https://assets.datacamp.com/production/repositories/3996/datasets/61e08004fef1a1b02b62620e3cd2533834239c90/student-alcohol-consumption.csv'
student_data = pd.read_csv(url)
print(student_data)
Unnamed: 0 school sex age famsize Pstatus Medu Fedu traveltime \
0 0 GP F 18 GT3 A 4 4 2
1 1 GP F 17 GT3 T 1 1 1
2 2 GP F 15 LE3 T 1 1 1
3 3 GP F 15 GT3 T 4 2 1
4 4 GP F 16 GT3 T 3 3 1
5 5 GP M 16 LE3 T 4 3 1
6 6 GP M 16 LE3 T 2 2 1
7 7 GP F 17 GT3 A 4 4 2
8 8 GP M 15 LE3 A 3 2 1
9 9 GP M 15 GT3 T 3 4 1
10 10 GP F 15 GT3 T 4 4 1
11 11 GP F 15 GT3 T 2 1 3
12 12 GP M 15 LE3 T 4 4 1
13 13 GP M 15 GT3 T 4 3 2
14 14 GP M 15 GT3 A 2 2 1
15 15 GP F 16 GT3 T 4 4 1
16 16 GP F 16 GT3 T 4 4 1
17 17 GP F 16 GT3 T 3 3 3
18 18 GP M 17 GT3 T 3 2 1
19 19 GP M 16 LE3 T 4 3 1
20 20 GP M 15 GT3 T 4 3 1
21 21 GP M 15 GT3 T 4 4 1
22 22 GP M 16 LE3 T 4 2 1
23 23 GP M 16 LE3 T 2 2 2
24 24 GP F 15 GT3 T 2 4 1
25 25 GP F 16 GT3 T 2 2 1
26 26 GP M 15 GT3 T 2 2 1
27 27 GP M 15 GT3 T 4 2 1
28 28 GP M 16 LE3 A 3 4 1
29 29 GP M 16 GT3 T 4 4 1
.. ... ... .. ... ... ... ... ... ...
365 365 MS M 18 GT3 T 1 3 2
366 366 MS M 18 LE3 T 4 4 2
367 367 MS F 17 GT3 T 1 1 3
368 368 MS F 18 GT3 T 2 3 2
369 369 MS F 18 GT3 T 4 4 3
370 370 MS F 19 LE3 T 3 2 2
371 371 MS M 18 LE3 T 1 2 3
372 372 MS F 17 GT3 T 2 2 1
373 373 MS F 17 GT3 T 1 2 1
374 374 MS F 18 LE3 T 4 4 2
375 375 MS F 18 GT3 T 1 1 4
376 376 MS F 20 GT3 T 4 2 2
377 377 MS F 18 LE3 T 4 4 1
378 378 MS F 18 GT3 T 3 3 1
379 379 MS F 17 GT3 T 3 1 1
380 380 MS M 18 GT3 T 4 4 1
381 381 MS M 18 GT3 T 2 1 2
382 382 MS M 17 GT3 T 2 3 2
383 383 MS M 19 GT3 T 1 1 2
384 384 MS M 18 GT3 T 4 2 2
385 385 MS F 18 GT3 T 2 2 2
386 386 MS F 18 GT3 T 4 4 3
387 387 MS F 19 GT3 T 2 3 1
388 388 MS F 18 LE3 T 3 1 1
389 389 MS F 18 GT3 T 1 1 2
390 390 MS M 20 LE3 A 2 2 1
391 391 MS M 17 LE3 T 3 1 2
392 392 MS M 21 GT3 T 1 1 1
393 393 MS M 18 LE3 T 3 2 3
394 394 MS M 19 LE3 T 1 1 1
failures ... goout Dalc Walc health absences G1 G2 G3 location \
0 0 ... 4 1 1 3 6 5 6 6 Urban
1 0 ... 3 1 1 3 4 5 5 6 Urban
2 3 ... 2 2 3 3 10 7 8 10 Urban
3 0 ... 2 1 1 5 2 15 14 15 Urban
4 0 ... 2 1 2 5 4 6 10 10 Urban
5 0 ... 2 1 2 5 10 15 15 15 Urban
6 0 ... 4 1 1 3 0 12 12 11 Urban
7 0 ... 4 1 1 1 6 6 5 6 Urban
8 0 ... 2 1 1 1 0 16 18 19 Urban
9 0 ... 1 1 1 5 0 14 15 15 Urban
10 0 ... 3 1 2 2 0 10 8 9 Urban
11 0 ... 2 1 1 4 4 10 12 12 Urban
12 0 ... 3 1 3 5 2 14 14 14 Urban
13 0 ... 3 1 2 3 2 10 10 11 Urban
14 0 ... 2 1 1 3 0 14 16 16 Urban
15 0 ... 4 1 2 2 4 14 14 14 Urban
16 0 ... 3 1 2 2 6 13 14 14 Urban
17 0 ... 2 1 1 4 4 8 10 10 Urban
18 3 ... 5 2 4 5 16 6 5 5 Urban
19 0 ... 3 1 3 5 4 8 10 10 Urban
20 0 ... 1 1 1 1 0 13 14 15 Urban
21 0 ... 2 1 1 5 0 12 15 15 Urban
22 0 ... 1 1 3 5 2 15 15 16 Urban
23 0 ... 4 2 4 5 0 13 13 12 Urban
24 0 ... 2 1 1 5 2 10 9 8 Rural
25 2 ... 2 1 3 5 14 6 9 8 Urban
26 0 ... 2 1 2 5 2 12 12 11 Urban
27 0 ... 4 2 4 1 4 15 16 15 Urban
28 0 ... 3 1 1 5 4 11 11 11 Urban
29 0 ... 5 5 5 5 16 10 12 11 Urban
.. ... ... ... ... ... ... ... .. .. .. ...
365 0 ... 4 2 4 3 4 10 10 10 Rural
366 0 ... 2 2 2 5 0 13 13 13 Urban
367 1 ... 1 1 2 1 0 7 6 0 Rural
368 0 ... 3 1 2 4 0 11 10 10 Urban
369 0 ... 2 4 2 5 10 14 12 11 Rural
370 2 ... 2 1 1 3 4 7 7 9 Urban
371 0 ... 3 2 3 3 3 14 12 12 Rural
372 0 ... 3 1 1 3 8 13 11 11 Urban
373 0 ... 5 1 3 1 14 6 5 5 Rural
374 0 ... 4 1 1 1 0 19 18 19 Rural
375 0 ... 2 1 2 4 2 8 8 10 Rural
376 2 ... 3 1 1 3 4 15 14 15 Urban
377 0 ... 3 3 4 2 4 8 9 10 Rural
378 0 ... 3 1 2 1 0 15 15 15 Urban
379 0 ... 4 2 3 1 17 10 10 10 Rural
380 0 ... 4 1 4 2 4 15 14 14 Urban
381 0 ... 3 1 3 5 5 7 6 7 Rural
382 0 ... 3 1 1 3 2 11 11 10 Urban
383 1 ... 2 1 3 5 0 6 5 0 Rural
384 1 ... 3 4 3 3 14 6 5 5 Rural
385 0 ... 3 1 3 4 2 10 9 10 Rural
386 0 ... 3 2 2 5 7 6 5 6 Rural
387 1 ... 2 1 2 5 0 7 5 0 Rural
388 0 ... 4 1 1 1 0 7 9 8 Urban
389 1 ... 1 1 1 5 0 6 5 0 Urban
390 2 ... 4 4 5 4 11 9 9 9 Urban
391 0 ... 5 3 4 2 3 14 16 16 Urban
392 3 ... 3 3 3 3 3 10 8 7 Rural
393 0 ... 1 3 4 5 0 11 12 10 Rural
394 0 ... 3 3 3 5 5 8 9 9 Urban
study_time
0 2 to 5 hours
1 2 to 5 hours
2 2 to 5 hours
3 5 to 10 hours
4 2 to 5 hours
5 2 to 5 hours
6 2 to 5 hours
7 2 to 5 hours
8 2 to 5 hours
9 2 to 5 hours
10 2 to 5 hours
11 5 to 10 hours
12 <2 hours
13 2 to 5 hours
14 5 to 10 hours
15 <2 hours
16 5 to 10 hours
17 2 to 5 hours
18 <2 hours
19 <2 hours
20 2 to 5 hours
21 <2 hours
22 2 to 5 hours
23 2 to 5 hours
24 5 to 10 hours
25 <2 hours
26 <2 hours
27 <2 hours
28 2 to 5 hours
29 2 to 5 hours
.. ...
365 2 to 5 hours
366 5 to 10 hours
367 <2 hours
368 <2 hours
369 2 to 5 hours
370 2 to 5 hours
371 <2 hours
372 5 to 10 hours
373 <2 hours
374 5 to 10 hours
375 5 to 10 hours
376 5 to 10 hours
377 2 to 5 hours
378 2 to 5 hours
379 2 to 5 hours
380 2 to 5 hours
381 <2 hours
382 2 to 5 hours
383 <2 hours
384 <2 hours
385 5 to 10 hours
386 <2 hours
387 5 to 10 hours
388 2 to 5 hours
389 2 to 5 hours
390 2 to 5 hours
391 <2 hours
392 <2 hours
393 <2 hours
394 <2 hours
[395 rows x 30 columns]
# Adjust to add subplots based on school support
sns.relplot(x="G1", y="G3",
data=student_data,
kind="scatter",
col = "schoolsup",
col_order=["yes", "no"])
# Show plot
plt.show()

# Adjust further to add subplots based on family support
sns.relplot(x="G1", y="G3",
data=student_data,
kind="scatter",
col="schoolsup",
col_order=["yes", "no"],
row="famsup",
row_order=["yes", "no"])
# Show plot
plt.show()

 

All the Contents are from DataCamp

 

Learn R, Python & Data Science Online

 

www.datacamp.com

 

Creating subplots with col and row

We've seen in prior exercises that students with more absences ("absences") tend to have lower final grades ("G3"). Does this relationship hold regardless of how much time students study each week?

To answer this, we'll look at the relationship between the number of absences that a student has in school and their final grade in the course, creating separate subplots based on each student's weekly study time ("study_time").

Seaborn has been imported as sns and matplotlib.pyplot has been imported as plt.

# Import Matplotlib and Seaborn
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
url = 'https://assets.datacamp.com/production/repositories/3996/datasets/61e08004fef1a1b02b62620e3cd2533834239c90/student-alcohol-consumption.csv'
student_data = pd.read_csv(url)
print(student_data)
Unnamed: 0 school sex age famsize Pstatus Medu Fedu traveltime \
0 0 GP F 18 GT3 A 4 4 2
1 1 GP F 17 GT3 T 1 1 1
2 2 GP F 15 LE3 T 1 1 1
3 3 GP F 15 GT3 T 4 2 1
4 4 GP F 16 GT3 T 3 3 1
5 5 GP M 16 LE3 T 4 3 1
6 6 GP M 16 LE3 T 2 2 1
7 7 GP F 17 GT3 A 4 4 2
8 8 GP M 15 LE3 A 3 2 1
9 9 GP M 15 GT3 T 3 4 1
10 10 GP F 15 GT3 T 4 4 1
11 11 GP F 15 GT3 T 2 1 3
12 12 GP M 15 LE3 T 4 4 1
13 13 GP M 15 GT3 T 4 3 2
14 14 GP M 15 GT3 A 2 2 1
15 15 GP F 16 GT3 T 4 4 1
16 16 GP F 16 GT3 T 4 4 1
17 17 GP F 16 GT3 T 3 3 3
18 18 GP M 17 GT3 T 3 2 1
19 19 GP M 16 LE3 T 4 3 1
20 20 GP M 15 GT3 T 4 3 1
21 21 GP M 15 GT3 T 4 4 1
22 22 GP M 16 LE3 T 4 2 1
23 23 GP M 16 LE3 T 2 2 2
24 24 GP F 15 GT3 T 2 4 1
25 25 GP F 16 GT3 T 2 2 1
26 26 GP M 15 GT3 T 2 2 1
27 27 GP M 15 GT3 T 4 2 1
28 28 GP M 16 LE3 A 3 4 1
29 29 GP M 16 GT3 T 4 4 1
.. ... ... .. ... ... ... ... ... ...
365 365 MS M 18 GT3 T 1 3 2
366 366 MS M 18 LE3 T 4 4 2
367 367 MS F 17 GT3 T 1 1 3
368 368 MS F 18 GT3 T 2 3 2
369 369 MS F 18 GT3 T 4 4 3
370 370 MS F 19 LE3 T 3 2 2
371 371 MS M 18 LE3 T 1 2 3
372 372 MS F 17 GT3 T 2 2 1
373 373 MS F 17 GT3 T 1 2 1
374 374 MS F 18 LE3 T 4 4 2
375 375 MS F 18 GT3 T 1 1 4
376 376 MS F 20 GT3 T 4 2 2
377 377 MS F 18 LE3 T 4 4 1
378 378 MS F 18 GT3 T 3 3 1
379 379 MS F 17 GT3 T 3 1 1
380 380 MS M 18 GT3 T 4 4 1
381 381 MS M 18 GT3 T 2 1 2
382 382 MS M 17 GT3 T 2 3 2
383 383 MS M 19 GT3 T 1 1 2
384 384 MS M 18 GT3 T 4 2 2
385 385 MS F 18 GT3 T 2 2 2
386 386 MS F 18 GT3 T 4 4 3
387 387 MS F 19 GT3 T 2 3 1
388 388 MS F 18 LE3 T 3 1 1
389 389 MS F 18 GT3 T 1 1 2
390 390 MS M 20 LE3 A 2 2 1
391 391 MS M 17 LE3 T 3 1 2
392 392 MS M 21 GT3 T 1 1 1
393 393 MS M 18 LE3 T 3 2 3
394 394 MS M 19 LE3 T 1 1 1
failures ... goout Dalc Walc health absences G1 G2 G3 location \
0 0 ... 4 1 1 3 6 5 6 6 Urban
1 0 ... 3 1 1 3 4 5 5 6 Urban
2 3 ... 2 2 3 3 10 7 8 10 Urban
3 0 ... 2 1 1 5 2 15 14 15 Urban
4 0 ... 2 1 2 5 4 6 10 10 Urban
5 0 ... 2 1 2 5 10 15 15 15 Urban
6 0 ... 4 1 1 3 0 12 12 11 Urban
7 0 ... 4 1 1 1 6 6 5 6 Urban
8 0 ... 2 1 1 1 0 16 18 19 Urban
9 0 ... 1 1 1 5 0 14 15 15 Urban
10 0 ... 3 1 2 2 0 10 8 9 Urban
11 0 ... 2 1 1 4 4 10 12 12 Urban
12 0 ... 3 1 3 5 2 14 14 14 Urban
13 0 ... 3 1 2 3 2 10 10 11 Urban
14 0 ... 2 1 1 3 0 14 16 16 Urban
15 0 ... 4 1 2 2 4 14 14 14 Urban
16 0 ... 3 1 2 2 6 13 14 14 Urban
17 0 ... 2 1 1 4 4 8 10 10 Urban
18 3 ... 5 2 4 5 16 6 5 5 Urban
19 0 ... 3 1 3 5 4 8 10 10 Urban
20 0 ... 1 1 1 1 0 13 14 15 Urban
21 0 ... 2 1 1 5 0 12 15 15 Urban
22 0 ... 1 1 3 5 2 15 15 16 Urban
23 0 ... 4 2 4 5 0 13 13 12 Urban
24 0 ... 2 1 1 5 2 10 9 8 Rural
25 2 ... 2 1 3 5 14 6 9 8 Urban
26 0 ... 2 1 2 5 2 12 12 11 Urban
27 0 ... 4 2 4 1 4 15 16 15 Urban
28 0 ... 3 1 1 5 4 11 11 11 Urban
29 0 ... 5 5 5 5 16 10 12 11 Urban
.. ... ... ... ... ... ... ... .. .. .. ...
365 0 ... 4 2 4 3 4 10 10 10 Rural
366 0 ... 2 2 2 5 0 13 13 13 Urban
367 1 ... 1 1 2 1 0 7 6 0 Rural
368 0 ... 3 1 2 4 0 11 10 10 Urban
369 0 ... 2 4 2 5 10 14 12 11 Rural
370 2 ... 2 1 1 3 4 7 7 9 Urban
371 0 ... 3 2 3 3 3 14 12 12 Rural
372 0 ... 3 1 1 3 8 13 11 11 Urban
373 0 ... 5 1 3 1 14 6 5 5 Rural
374 0 ... 4 1 1 1 0 19 18 19 Rural
375 0 ... 2 1 2 4 2 8 8 10 Rural
376 2 ... 3 1 1 3 4 15 14 15 Urban
377 0 ... 3 3 4 2 4 8 9 10 Rural
378 0 ... 3 1 2 1 0 15 15 15 Urban
379 0 ... 4 2 3 1 17 10 10 10 Rural
380 0 ... 4 1 4 2 4 15 14 14 Urban
381 0 ... 3 1 3 5 5 7 6 7 Rural
382 0 ... 3 1 1 3 2 11 11 10 Urban
383 1 ... 2 1 3 5 0 6 5 0 Rural
384 1 ... 3 4 3 3 14 6 5 5 Rural
385 0 ... 3 1 3 4 2 10 9 10 Rural
386 0 ... 3 2 2 5 7 6 5 6 Rural
387 1 ... 2 1 2 5 0 7 5 0 Rural
388 0 ... 4 1 1 1 0 7 9 8 Urban
389 1 ... 1 1 1 5 0 6 5 0 Urban
390 2 ... 4 4 5 4 11 9 9 9 Urban
391 0 ... 5 3 4 2 3 14 16 16 Urban
392 3 ... 3 3 3 3 3 10 8 7 Rural
393 0 ... 1 3 4 5 0 11 12 10 Rural
394 0 ... 3 3 3 5 5 8 9 9 Urban
study_time
0 2 to 5 hours
1 2 to 5 hours
2 2 to 5 hours
3 5 to 10 hours
4 2 to 5 hours
5 2 to 5 hours
6 2 to 5 hours
7 2 to 5 hours
8 2 to 5 hours
9 2 to 5 hours
10 2 to 5 hours
11 5 to 10 hours
12 <2 hours
13 2 to 5 hours
14 5 to 10 hours
15 <2 hours
16 5 to 10 hours
17 2 to 5 hours
18 <2 hours
19 <2 hours
20 2 to 5 hours
21 <2 hours
22 2 to 5 hours
23 2 to 5 hours
24 5 to 10 hours
25 <2 hours
26 <2 hours
27 <2 hours
28 2 to 5 hours
29 2 to 5 hours
.. ...
365 2 to 5 hours
366 5 to 10 hours
367 <2 hours
368 <2 hours
369 2 to 5 hours
370 2 to 5 hours
371 <2 hours
372 5 to 10 hours
373 <2 hours
374 5 to 10 hours
375 5 to 10 hours
376 5 to 10 hours
377 2 to 5 hours
378 2 to 5 hours
379 2 to 5 hours
380 2 to 5 hours
381 <2 hours
382 2 to 5 hours
383 <2 hours
384 <2 hours
385 5 to 10 hours
386 <2 hours
387 5 to 10 hours
388 2 to 5 hours
389 2 to 5 hours
390 2 to 5 hours
391 <2 hours
392 <2 hours
393 <2 hours
394 <2 hours
[395 rows x 30 columns]
# Change to make subplots based on study time
sns.relplot(x="absences", y="G3",
data=student_data,
kind="scatter")
# Show plot
plt.show()

# Modify the code to create one scatter plot for each level of the variable "study_time", arranged in columns.
sns.relplot(x="absences", y="G3",
data=student_data,
kind="scatter", col = "study_time")
# Show plot
plt.show()

# Adapt your code to create one scatter plot for each level of a student's weekly study time, this time arranged in rows.
# Change this scatter plot to arrange the plots in rows instead of columns
sns.relplot(x="absences", y="G3",
data=student_data,
kind="scatter",
row="study_time")
# Show plot
plt.show()

All the Contents Are from DataCamp

 

Learn R, Python & Data Science Online

 

www.datacamp.com

+ Recent posts