welcome to the co u rse
play

Welcome to the co u rse ! VISU AL IZIN G TIME SE R IE S DATA IN P - PowerPoint PPT Presentation

Welcome to the co u rse ! VISU AL IZIN G TIME SE R IE S DATA IN P YTH ON Thomas Vincent Head of Data Science , Ge y Images Prereq u isites Intro to P y thon for Data Science Intermediate P y thon for Data Science VISUALIZING TIME SERIES


  1. Welcome to the co u rse ! VISU AL IZIN G TIME SE R IE S DATA IN P YTH ON Thomas Vincent Head of Data Science , Ge � y Images

  2. Prereq u isites Intro to P y thon for Data Science Intermediate P y thon for Data Science VISUALIZING TIME SERIES DATA IN PYTHON

  3. Time series in the field of Data Science Time series are a f u ndamental w a y to store and anal yz e man y t y pes of data Financial , w eather and de v ice data are all best handled as time series VISUALIZING TIME SERIES DATA IN PYTHON

  4. Time series in the field of Data Science VISUALIZING TIME SERIES DATA IN PYTHON

  5. Co u rse o v er v ie w Chapter 1: Ge � ing started and personali z ing y o u r � rst time series plot Chapter 2: S u mmari z ing and describing time series data Chapter 3: Ad v anced time series anal y sis Chapter 4: Working w ith m u ltiple time series Chapter 5: Case St u d y VISUALIZING TIME SERIES DATA IN PYTHON

  6. Reading data w ith Pandas import pandas as pd df = pd.read_csv('ch2_co2_levels.csv') print(df) datestamp co2 0 1958-03-29 316.1 1 1958-04-05 317.3 2 1958-04-12 317.6 ... ... ... 2281 2001-12-15 371.2 2282 2001-12-22 371.3 2283 2001-12-29 371.5 VISUALIZING TIME SERIES DATA IN PYTHON

  7. Pre v ie w data w ith Pandas print(df.head(n=5)) datestamp co2 0 1958-03-29 316.1 1 1958-04-05 317.3 2 1958-04-12 317.6 3 1958-04-19 317.5 4 1958-04-26 316.4 print(df.tail(n=5)) datestamp co2 2279 2001-12-01 370.3 2280 2001-12-08 370.8 2281 2001-12-15 371.2 2282 2001-12-22 371.3 2283 2001-12-29 371.5 VISUALIZING TIME SERIES DATA IN PYTHON

  8. Check data t y pes w ith Pandas print(df.dtypes) datestamp object co2 float64 dtype: object VISUALIZING TIME SERIES DATA IN PYTHON

  9. Working w ith dates To w ork w ith time series data in pandas , y o u r date col u mns needs to be of the datetime64 t y pe . pd.to_datetime(['2009/07/31', 'test']) ValueError: Unknown string format pd.to_datetime(['2009/07/31', 'test'], errors='coerce') DatetimeIndex(['2009-07-31', 'NaT'], dtype='datetime64[ns]', freq=None) VISUALIZING TIME SERIES DATA IN PYTHON

  10. Let ' s get started ! VISU AL IZIN G TIME SE R IE S DATA IN P YTH ON

  11. Plot y o u r first time series VISU AL IZIN G TIME SE R IE S DATA IN P YTH ON Thomas Vincent Head of Data Science , Ge � y Images

  12. The Matplotlib librar y In P y thon , matplotlib is an e x tensi v e package u sed to plot data The p y plot s u bmod u le of matplotlib is traditionall y imported u sing the plt alias import matplotlib.pyplot as plt VISUALIZING TIME SERIES DATA IN PYTHON

  13. Plotting time series data VISUALIZING TIME SERIES DATA IN PYTHON

  14. Plotting time series data import matplotlib.pyplot as plt import pandas as pd df = df.set_index('date_column') df.plot() plt.show() VISUALIZING TIME SERIES DATA IN PYTHON

  15. Adding st y le to y o u r plots plt.style.use('fivethirtyeight') df.plot() plt.show() VISUALIZING TIME SERIES DATA IN PYTHON

  16. Fi v eThirt y Eight st y le VISUALIZING TIME SERIES DATA IN PYTHON

  17. Matplotlib st y le sheets print(plt.style.available) ['seaborn-dark-palette', 'seaborn-darkgrid', 'seaborn-dark', 'seaborn-notebook', 'seaborn-pastel', 'seaborn-white', 'classic', 'ggplot', 'grayscale', 'dark_background', 'seaborn-poster', 'seaborn-muted', 'seaborn', 'bmh', 'seaborn-paper', 'seaborn-whitegrid', 'seaborn-bright', 'seaborn-talk', 'fivethirtyeight', 'seaborn-colorblind', 'seaborn-deep', 'seaborn-ticks'] VISUALIZING TIME SERIES DATA IN PYTHON

  18. Describing y o u r graphs w ith labels ax = df.plot(color='blue') ax.set_xlabel('Date') ax.set_ylabel('The values of my Y axis') ax.set_title('The title of my plot') plt.show() VISUALIZING TIME SERIES DATA IN PYTHON

  19. Fig u re si z e , line w idth , linest y le and fontsi z e ax = df.plot(figsize=(12, 5), fontsize=12, linewidth=3, linestyle='--') ax.set_xlabel('Date', fontsize=16) ax.set_ylabel('The values of my Y axis', fontsize=16) ax.set_title('The title of my plot', fontsize=16) plt.show() VISUALIZING TIME SERIES DATA IN PYTHON

  20. Let ' s practice ! VISU AL IZIN G TIME SE R IE S DATA IN P YTH ON

  21. C u stomi z e y o u r time series plot VISU AL IZIN G TIME SE R IE S DATA IN P YTH ON Thomas Vincent Head of Data Science , Ge � y Images

  22. Slicing time series data discoveries['1960':'1970'] discoveries['1950-01':'1950-12'] discoveries['1960-01-01':'1960-01-15'] VISUALIZING TIME SERIES DATA IN PYTHON

  23. Plotting s u bset of y o u r time series data import matplotlib.pyplot as plt plt.style.use('fivethirtyeight') df_subset = discoveries['1960':'1970'] ax = df_subset.plot(color='blue', fontsize=14) plt.show() VISUALIZING TIME SERIES DATA IN PYTHON

  24. Adding markers ax.axvline(x='1969-01-01', color='red', linestyle='--') ax.axhline(y=100, color='green', linestyle='--') VISUALIZING TIME SERIES DATA IN PYTHON

  25. Using markers : the f u ll code ax = discoveries.plot(color='blue') ax.set_xlabel('Date') ax.set_ylabel('Number of great discoveries') ax.axvline('1969-01-01', color='red', linestyle='--') ax.axhline(4, color='green', linestyle='--') VISUALIZING TIME SERIES DATA IN PYTHON

  26. Highlighting regions of interest ax.axvspan('1964-01-01', '1968-01-01', color='red', alpha=0.5) ax.axhspan(8, 6, color='green', alpha=0.2) VISUALIZING TIME SERIES DATA IN PYTHON

  27. Highlighting regions of interest : the f u ll code ax = discoveries.plot(color='blue') ax.set_xlabel('Date') ax.set_ylabel('Number of great discoveries') ax.axvspan('1964-01-01', '1968-01-01', color='red', alpha=0.3) ax.axhspan(8, 6, color='green', alpha=0.3) VISUALIZING TIME SERIES DATA IN PYTHON

  28. Let ' s practice ! VISU AL IZIN G TIME SE R IE S DATA IN P YTH ON

Recommend


More recommend