Forest_Fires

.pdf

School

Northeastern University *

*We aren’t endorsed by this school

Course

7275

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

pdf

Pages

10

Uploaded by MasterChinchillaPerson721 on coursehero.com

In [7]: #Q.2 from google.colab import files import pandas as pd import matplotlib.pyplot as plt uploaded = files . upload() df = pd . read_csv( 'forestfires.csv' ) In [9]: df = pd . DataFrame(df) In [16]: df . sort_values( 'month' ,ascending = True ) Choose Files No file chosen Upload widget is only available when the cell has been executed in the current browser session. Please rerun this cell to enable. Saving forestfires.csv to forestfires (1).csv Out[16]: X Y month day FFMC DMC DC ISI temp RH wind rain area 442 6 5 apr mon 87.9 24.9 41.6 3.7 10.9 64 3.1 0.0 3.35 241 4 4 apr fri 83.0 23.3 85.3 2.3 16.7 20 3.1 0.0 0.00 176 6 5 apr thu 81.5 9.1 55.2 2.7 5.8 54 5.8 0.0 4.61 240 6 3 apr wed 88.0 17.2 43.5 3.8 15.2 51 2.7 0.0 0.00 196 6 5 apr thu 81.5 9.1 55.2 2.7 5.8 54 5.8 0.0 10.93 ... ... ... ... ... ... ... ... ... ... ... ... ... ... 366 4 5 sep tue 91.1 132.3 812.1 12.5 15.9 38 5.4 0.0 1.75 367 4 5 sep tue 91.1 132.3 812.1 12.5 16.4 27 3.6 0.0 0.00 368 6 5 sep sat 91.2 94.3 744.4 8.4 16.8 47 4.9 0.0 12.64 357 6 3 sep fri 92.5 122.0 789.7 10.2 15.9 55 3.6 0.0 0.00 173 4 4 sep mon 90.9 126.5 686.5 7.0 17.7 39 2.2 0.0 3.07 517 rows × 13 columns
In [17]: df Out[17]: X Y month day FFMC DMC DC ISI temp RH wind rain area 0 7 5 mar fri 86.2 26.2 94.3 5.1 8.2 51 6.7 0.0 0.00 1 7 4 oct tue 90.6 35.4 669.1 6.7 18.0 33 0.9 0.0 0.00 2 7 4 oct sat 90.6 43.7 686.9 6.7 14.6 33 1.3 0.0 0.00 3 8 6 mar fri 91.7 33.3 77.5 9.0 8.3 97 4.0 0.2 0.00 4 8 6 mar sun 89.3 51.3 102.2 9.6 11.4 99 1.8 0.0 0.00 ... ... ... ... ... ... ... ... ... ... ... ... ... ... 512 4 3 aug sun 81.6 56.7 665.6 1.9 27.8 32 2.7 0.0 6.44 513 2 4 aug sun 81.6 56.7 665.6 1.9 21.9 71 5.8 0.0 54.29 514 7 4 aug sun 81.6 56.7 665.6 1.9 21.2 70 6.7 0.0 11.16 515 1 4 aug sat 94.4 146.0 614.7 11.3 25.6 42 4.0 0.0 0.00 516 6 3 nov tue 79.5 3.0 106.7 1.1 11.8 31 4.5 0.0 0.00 517 rows × 13 columns
In [18]: #1 month_order = [ 'jan' , 'feb' , 'mar' , 'apr' , 'may' , 'jun' , 'jul' , 'aug' , 'sep' , 'oct' , 'no v' , 'dec' ] grouped = df . groupby([ 'month' , 'day' ]) . size() . unstack() . reindex(month_order) grouped . plot(kind = 'bar' , stacked = True ) plt . xlabel( 'Month' ) plt . ylabel( 'Number of Forest Fires' ) plt . title( 'Forest Fires by Month and Day' ) plt . show() 1. Yes, the issue with the stacked bar chart is the information is very hard to read in the stacked bar chart. So we can use different types of visualizations such as heatmap to better get the information.
In [19]: pivot_table = df . pivot_table(index = 'month' , columns = 'day' , aggfunc = 'size' , fill_value =0 ) pivot_table In [20]: #2 scatter_fire = df . plot . scatter( 'X' , 'Y' ,s = 'area' ,c = 'red' ) Out[19]: day fri mon sat sun thu tue wed month apr 1 1 1 3 2 0 1 aug 21 15 29 40 26 28 25 dec 1 4 0 1 1 1 1 feb 5 3 4 4 1 2 1 jan 0 0 1 1 0 0 0 jul 3 4 8 5 3 6 3 jun 3 3 2 4 2 0 3 mar 11 12 10 7 5 5 4 may 1 0 1 0 0 0 0 nov 0 0 0 0 0 1 0 oct 1 4 3 3 0 2 2 sep 38 28 25 27 21 19 14
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help