SlideShare a Scribd company logo
UNIT 5:
REAL TIME DATA ANALYSIS
DR.V.S.PRAKASH | V BCA 1
TIME SERIES
Time series analysis is a crucial part of data analysis, and Python provides several tools and libraries for working
with time series data.
DR.V.S.PRAKASH | V BCA 2
Date and Time Data Types and Tools:
Datetime Module:
Python's standard library includes the datetime module, which provides classes for working with dates and
times. You can use the datetime class to represent both date and time information.
from datetime import datetime
now = datetime.now() # Current date and time
print(now)
Date and Time Objects:
The datetime module includes date and time classes that allow you to work with just the date or time portion.
DR.V.S.PRAKASH | V BCA 3
String to Datetime Conversion:
You can convert a string representing a date and time to a datetime object using the strptime method.
date_str = "2023-10-24"
datetime_obj = datetime.strptime(date_str, "%Y-%m-%d")
Datetime to String Conversion:
To convert a datetime object back to a string, you can use the strftime method.
formatted_date = datetime_obj.strftime("%Y-%m-%d")
DR.V.S.PRAKASH | V BCA 4
DR.V.S.PRAKASH | V BCA 5
DR.V.S.PRAKASH | V BCA 6
DR.V.S.PRAKASH | V BCA 7
TIME SERIES BASICS:
Time series data consists of data points collected or recorded at successive, equally spaced time intervals.
Common examples of time series data include stock prices, temperature measurements, and website traffic.
Here are some fundamental concepts and tools for working with time series data in Python:
Pandas: The Pandas library is a powerful tool for working with time series data. It provides data structures like
DataFrame and Series that are ideal for organizing and analyzing time series data.
import pandas as pd
time_series_data = pd.Series([10, 20, 30, 40], index=pd.date_range(start='2023-10-01', periods=4, freq='D')
DR.V.S.PRAKASH | V BCA 8
Time Resampling:
You can resample time series data to change the frequency of data points (e.g., from daily to monthly) using
Pandas' resample method.
Pandas dataframe.resample() function is primarily used for time series data.
A time series is a series of data points indexed (or listed or graphed) in time order. Most commonly, a time
series is a sequence taken at successive equally spaced points in time. It is a Convenience method for
frequency conversion and resampling of time series.
monthly_data = time_series_data.resample('M').mean()
Plotting Time Series Data:
Libraries like Matplotlib and Seaborn can be used to visualize time series data.
import matplotlib.pyplot as plt
time_series_data.plot()
plt.xlabel("Date")
plt.ylabel("Value")
plt.show()
DR.V.S.PRAKASH | V BCA 9
Time Series Analysis:
You can perform various time series analysis tasks, including trend analysis, seasonality detection, and
forecasting, using tools like Statsmodels and Scikit-learn.
from statsmodels.tsa.seasonal import seasonal_decompose
decomposition = seasonal_decompose(time_series_data)
trend = decomposition.trend
seasonal = decomposition.seasonal
Time series decomposition involves thinking of a series as a combination of level, trend, seasonality, and noise
noise components.
• Level: The average value in the series.
• Trend: The increasing or decreasing value in the series.
• Seasonality: The repeating short-term cycle in the series.
• Noise: The random variation in the series.
DR.V.S.PRAKASH | V BCA 10
INDEXING AND SELECTION:
Selecting by Index:
You can access specific elements in a time series using index labels.
import pandas as pd
time_series_data = pd.Series([10, 20, 30, 40], index=pd.date_range(start='2023-10-01', periods=4, freq='D'))
selected_data = time_series_data['2023-10-01']
Selecting by Slicing: Use slicing to select a range of data.
selected_range = time_series_data['2023-10-01':'2023-10-03']
Subsetting by Conditions:
You can subset time series data based on conditions using boolean indexing.
subset = time_series_data[time_series_data > 20]
DR.V.S.PRAKASH | V BCA 11
Date Ranges and Frequencies:
Date Ranges: You can create date ranges using Pandas' date_range function. This is useful for generating date
index for time series data.
date_range = pd.date_range(start='2023-10-01', end='2023-10-10', freq='D')
Frequencies: You can specify various frequencies when creating date ranges. Common frequencies include 'D'
(day), 'H' (hour), 'M' (month end), and more.
hourly_range = pd.date_range(start='2023-10-01', periods=24, freq='H')
monthly_range = pd.date_range(start='2023-01-01', end='2023-12-31', freq='M')
Shifting Data:
Shifting is a common operation when working with time series data, often used for calculating differences or
creating lag features.
Shift Data: You can shift the data forward or backward using the shift method.
shifted_data = time_series_data.shift(periods=1) # Shift data one period forward
Calculating Differences: To compute the difference between consecutive values, you can subtract the shifted
series.
DR.V.S.PRAKASH | V BCA 12
SHIFTING DATA:
Shifting data involves moving time series data forward or backward in time. This is useful for various time series
analysis tasks.
Shift Data: You can shift data using Pandas' shift method.
The simplest call should have an argument periods (It defaults to 1) and it represents the number of shifts for the
desired axis. And by default, it is shifting values vertically along the axis 0 . NaN will be filled for missing values
introduced as a result of the shifting.
import pandas as pd
# Shifting data one period forward
shifted_data = time_series_data.shift(periods=1)
# Shifting data two periods backward
shifted_data = time_series_data.shift(periods=-2)
Calculating Differences: Shifting is often used to calculate the differences between consecutive values.
# Calculate the difference between consecutive values
DR.V.S.PRAKASH | V BCA 13
Generating Date Ranges and Frequencies:
Pandas provides powerful tools for generating date ranges with different frequencies.
Date Ranges: Use the date_range function to create date ranges.
date_range = pd.date_range(start='2023-01-01', end='2023-12-31', freq='D') # Daily frequency
Frequencies: You can specify various frequencies such as 'D' (day), 'H' (hour), 'M' (month end), 'Y' (year end),
and more when creating date ranges.
hourly_range = pd.date_range(start='2023-01-01', periods=24, freq='H')
monthly_range = pd.date_range(start='2023-01-01', end='2023-12-31', freq='M')
DR.V.S.PRAKASH | V BCA 14
Time Zone Handling:
Pandas can handle time zones and convert between them.
Setting Time Zone:
time_series_data = time_series_data.tz_localize('UTC') # Set time zone to UTC
Converting Time Zones:
time_series_data = time_series_data.tz_convert('US/Eastern') # Convert to US Eastern Time
Quarterly Period Frequencies:
Quarterly periods can be generated with the "Q" frequency code.
quarterly_range = pd.period_range(start='2023Q1', end='2023Q4', freq='Q')
DR.V.S.PRAKASH | V BCA 15
TIME SERIES ANALYSIS
Time series analysis often involves various data manipulation tasks, including plotting, data munging,
splicing data from multiple sources, decile and quartile analysis, and more. Let's explore these concepts and
some sample applications in the context of time series analysis:
Time Series Plotting:
Plotting is crucial for visualizing time series data to identify patterns and trends.
import matplotlib.pyplot as plt
# Plot time series data
time_series_data.plot()
plt.xlabel("Date")
plt.ylabel("Value")
plt.title("Time Series Plot")
plt.show()
DR.V.S.PRAKASH | V BCA 16
Data Munging:
Data munging involves cleaning, transforming, and preparing data for analysis. In time series analysis, this might
include handling missing values, resampling, or dealing with outliers.
# Handling missing values
time_series_data = time_series_data.fillna(method='ffill')
# Resampling to a different frequency
resampled_data = time_series_data.resample('W').mean()
Splicing Together Data Sources:
In some cases, you may need to combine time series data from multiple sources.
import pandas as pd
# Concatenating data from multiple sources
combined_data = pd.concat([data_source1, data_source2])
Decile and Quartile Analysis:
Decile and quartile analysis helps you understand the distribution of data.
# Calculate quartiles
quartiles = time_series_data.quantile([0.25, 0.5, 0.75])
# Calculate deciles
deciles = time_series_data.quantile([i/10 for i in range(1, 10)])
DR.V.S.PRAKASH | V BCA 17
Sample Applications:
Stock Market Analysis: Analyzing stock price time series data for trends and predicting future stock prices.
Temperature Forecasting: Analyzing historical temperature data to forecast future weather conditions.
Demand Forecasting: Analyzing sales data to forecast future product demand.
Future Contract Rolling:
In financial time series analysis, rolling futures contracts is crucial to avoid jumps in time series data when
contracts expire.
# Rolling futures contracts in a DataFrame
rolled_data = contract_rolling_function(time_series_data, window=10)
Rolling Correlation and Linear Regression:
Rolling correlation and regression are used to understand how the relationship between two time series
changes over time.
# Calculate rolling correlation between two time series
rolling_corr = time_series_data1.rolling(window=30).corr(time_series_data2)
# Calculate rolling linear regression between two time series
rolling_regression = time_series_data1.rolling(window=30).apply(lambda x: your_lin
DR.V.S.PRAKASH | V BCA 18
DR.V.S.PRAKASH | V BCA 19
Data Munging:
Data munging is a more general term that encompasses various data preparation tasks, including
cleaning, structuring, and organizing data.
It often involves dealing with missing data, handling outliers, and addressing issues like data
format inconsistencies.
Data munging can also include tasks such as data loading, data extraction, and basic data
exploration.
It is a broader term that doesn't specify a particular methodology or approach.
Data Wrangling:
Data wrangling is a subset of data munging that specifically refers to the process of cleaning,
transforming, and structuring data for analysis.
Data wrangling typically involves tasks like filtering, aggregating, joining, and reshaping data to
create a dataset that is ready for analysis or machine learning.
It is often associated with data preparation in the context of data analysis and is more focused on
making data suitable for specific analytical tasks.

More Related Content

Similar to unit 5_Real time Data Analysis vsp.pptx

XII - 2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
XII -  2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdfXII -  2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
XII - 2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
KrishnaJyotish1
 
Anomaly Detection using Neural Networks with Pandas, Keras and Python
Anomaly Detection using Neural Networks with Pandas, Keras and PythonAnomaly Detection using Neural Networks with Pandas, Keras and Python
Anomaly Detection using Neural Networks with Pandas, Keras and Python
Dean Langsam
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineering
Julian Hyde
 
Apache Cassandra for Timeseries- and Graph-Data
Apache Cassandra for Timeseries- and Graph-DataApache Cassandra for Timeseries- and Graph-Data
Apache Cassandra for Timeseries- and Graph-Data
Guido Schmutz
 
Using the python_data_toolkit_timbers_slides
Using the python_data_toolkit_timbers_slidesUsing the python_data_toolkit_timbers_slides
Using the python_data_toolkit_timbers_slides
Tiffany Timbers
 
Introduction to Data Science With R Notes
Introduction to Data Science With R NotesIntroduction to Data Science With R Notes
Introduction to Data Science With R Notes
LakshmiSarvani6
 
Assignment Details There is a .h file on Moodle that provides a defi.pdf
Assignment Details There is a .h file on Moodle that provides a defi.pdfAssignment Details There is a .h file on Moodle that provides a defi.pdf
Assignment Details There is a .h file on Moodle that provides a defi.pdf
jyothimuppasani1
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
RaajTech
 
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Yao Yao
 
DSE-complete.pptx
DSE-complete.pptxDSE-complete.pptx
DSE-complete.pptx
RanjithKumar888622
 
Best Practices: How to Analyze IoT Sensor Data with InfluxDB
Best Practices: How to Analyze IoT Sensor Data with InfluxDBBest Practices: How to Analyze IoT Sensor Data with InfluxDB
Best Practices: How to Analyze IoT Sensor Data with InfluxDB
InfluxData
 
Teradata 13.10
Teradata 13.10Teradata 13.10
Teradata 13.10
Teradata
 
Time series.ppt
Time series.pptTime series.ppt
Time series.ppt
SauravDash10
 
SessionSeven_WorkingWithDatesandTime
SessionSeven_WorkingWithDatesandTimeSessionSeven_WorkingWithDatesandTime
SessionSeven_WorkingWithDatesandTimeHellen Gakuruh
 
Data manipulation on r
Data manipulation on rData manipulation on r
Data manipulation on r
Abhik Seal
 
Unit5_Time Series Analysis.pdf
Unit5_Time Series  Analysis.pdfUnit5_Time Series  Analysis.pdf
Unit5_Time Series Analysis.pdf
Karanvhatkar1
 
Numerical data.
Numerical data.Numerical data.
Numerical data.
Adewumi Ezekiel Adebayo
 
Multi-Step-Ahead Simultaneously Forecasting For Multiple Time-Series, Using T...
Multi-Step-Ahead Simultaneously Forecasting For Multiple Time-Series, Using T...Multi-Step-Ahead Simultaneously Forecasting For Multiple Time-Series, Using T...
Multi-Step-Ahead Simultaneously Forecasting For Multiple Time-Series, Using T...
Florian Cartuta
 
SAS functions.pptx
SAS functions.pptxSAS functions.pptx
SAS functions.pptx
SanjeevaniClinicalRe
 
Workflow Scheduling Techniques and Algorithms in IaaS Cloud: A Survey
Workflow Scheduling Techniques and Algorithms in IaaS Cloud: A Survey Workflow Scheduling Techniques and Algorithms in IaaS Cloud: A Survey
Workflow Scheduling Techniques and Algorithms in IaaS Cloud: A Survey
IJECEIAES
 

Similar to unit 5_Real time Data Analysis vsp.pptx (20)

XII - 2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
XII -  2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdfXII -  2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
XII - 2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
 
Anomaly Detection using Neural Networks with Pandas, Keras and Python
Anomaly Detection using Neural Networks with Pandas, Keras and PythonAnomaly Detection using Neural Networks with Pandas, Keras and Python
Anomaly Detection using Neural Networks with Pandas, Keras and Python
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineering
 
Apache Cassandra for Timeseries- and Graph-Data
Apache Cassandra for Timeseries- and Graph-DataApache Cassandra for Timeseries- and Graph-Data
Apache Cassandra for Timeseries- and Graph-Data
 
Using the python_data_toolkit_timbers_slides
Using the python_data_toolkit_timbers_slidesUsing the python_data_toolkit_timbers_slides
Using the python_data_toolkit_timbers_slides
 
Introduction to Data Science With R Notes
Introduction to Data Science With R NotesIntroduction to Data Science With R Notes
Introduction to Data Science With R Notes
 
Assignment Details There is a .h file on Moodle that provides a defi.pdf
Assignment Details There is a .h file on Moodle that provides a defi.pdfAssignment Details There is a .h file on Moodle that provides a defi.pdf
Assignment Details There is a .h file on Moodle that provides a defi.pdf
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
 
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
 
DSE-complete.pptx
DSE-complete.pptxDSE-complete.pptx
DSE-complete.pptx
 
Best Practices: How to Analyze IoT Sensor Data with InfluxDB
Best Practices: How to Analyze IoT Sensor Data with InfluxDBBest Practices: How to Analyze IoT Sensor Data with InfluxDB
Best Practices: How to Analyze IoT Sensor Data with InfluxDB
 
Teradata 13.10
Teradata 13.10Teradata 13.10
Teradata 13.10
 
Time series.ppt
Time series.pptTime series.ppt
Time series.ppt
 
SessionSeven_WorkingWithDatesandTime
SessionSeven_WorkingWithDatesandTimeSessionSeven_WorkingWithDatesandTime
SessionSeven_WorkingWithDatesandTime
 
Data manipulation on r
Data manipulation on rData manipulation on r
Data manipulation on r
 
Unit5_Time Series Analysis.pdf
Unit5_Time Series  Analysis.pdfUnit5_Time Series  Analysis.pdf
Unit5_Time Series Analysis.pdf
 
Numerical data.
Numerical data.Numerical data.
Numerical data.
 
Multi-Step-Ahead Simultaneously Forecasting For Multiple Time-Series, Using T...
Multi-Step-Ahead Simultaneously Forecasting For Multiple Time-Series, Using T...Multi-Step-Ahead Simultaneously Forecasting For Multiple Time-Series, Using T...
Multi-Step-Ahead Simultaneously Forecasting For Multiple Time-Series, Using T...
 
SAS functions.pptx
SAS functions.pptxSAS functions.pptx
SAS functions.pptx
 
Workflow Scheduling Techniques and Algorithms in IaaS Cloud: A Survey
Workflow Scheduling Techniques and Algorithms in IaaS Cloud: A Survey Workflow Scheduling Techniques and Algorithms in IaaS Cloud: A Survey
Workflow Scheduling Techniques and Algorithms in IaaS Cloud: A Survey
 

More from prakashvs7

Python lambda.pptx
Python lambda.pptxPython lambda.pptx
Python lambda.pptx
prakashvs7
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptx
prakashvs7
 
Unit 4_Working with Graphs _python (2).pptx
Unit 4_Working with Graphs _python (2).pptxUnit 4_Working with Graphs _python (2).pptx
Unit 4_Working with Graphs _python (2).pptx
prakashvs7
 
unit 4-1.pptx
unit 4-1.pptxunit 4-1.pptx
unit 4-1.pptx
prakashvs7
 
unit 3.ppt
unit 3.pptunit 3.ppt
unit 3.ppt
prakashvs7
 
final Unit 1-1.pdf
final Unit 1-1.pdffinal Unit 1-1.pdf
final Unit 1-1.pdf
prakashvs7
 
PCCF-UNIT 2-1 new.docx
PCCF-UNIT 2-1 new.docxPCCF-UNIT 2-1 new.docx
PCCF-UNIT 2-1 new.docx
prakashvs7
 
AI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptxAI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptx
prakashvs7
 
AI UNIT-3 FINAL (1).pptx
AI UNIT-3 FINAL (1).pptxAI UNIT-3 FINAL (1).pptx
AI UNIT-3 FINAL (1).pptx
prakashvs7
 
AI-UNIT 1 FINAL PPT (2).pptx
AI-UNIT 1 FINAL PPT (2).pptxAI-UNIT 1 FINAL PPT (2).pptx
AI-UNIT 1 FINAL PPT (2).pptx
prakashvs7
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
prakashvs7
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
prakashvs7
 
DS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptxDS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptx
prakashvs7
 
Php unit i
Php unit i Php unit i
Php unit i
prakashvs7
 
The process
The processThe process
The process
prakashvs7
 

More from prakashvs7 (15)

Python lambda.pptx
Python lambda.pptxPython lambda.pptx
Python lambda.pptx
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptx
 
Unit 4_Working with Graphs _python (2).pptx
Unit 4_Working with Graphs _python (2).pptxUnit 4_Working with Graphs _python (2).pptx
Unit 4_Working with Graphs _python (2).pptx
 
unit 4-1.pptx
unit 4-1.pptxunit 4-1.pptx
unit 4-1.pptx
 
unit 3.ppt
unit 3.pptunit 3.ppt
unit 3.ppt
 
final Unit 1-1.pdf
final Unit 1-1.pdffinal Unit 1-1.pdf
final Unit 1-1.pdf
 
PCCF-UNIT 2-1 new.docx
PCCF-UNIT 2-1 new.docxPCCF-UNIT 2-1 new.docx
PCCF-UNIT 2-1 new.docx
 
AI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptxAI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptx
 
AI UNIT-3 FINAL (1).pptx
AI UNIT-3 FINAL (1).pptxAI UNIT-3 FINAL (1).pptx
AI UNIT-3 FINAL (1).pptx
 
AI-UNIT 1 FINAL PPT (2).pptx
AI-UNIT 1 FINAL PPT (2).pptxAI-UNIT 1 FINAL PPT (2).pptx
AI-UNIT 1 FINAL PPT (2).pptx
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
 
DS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptxDS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptx
 
Php unit i
Php unit i Php unit i
Php unit i
 
The process
The processThe process
The process
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 

unit 5_Real time Data Analysis vsp.pptx

  • 1. UNIT 5: REAL TIME DATA ANALYSIS DR.V.S.PRAKASH | V BCA 1
  • 2. TIME SERIES Time series analysis is a crucial part of data analysis, and Python provides several tools and libraries for working with time series data. DR.V.S.PRAKASH | V BCA 2
  • 3. Date and Time Data Types and Tools: Datetime Module: Python's standard library includes the datetime module, which provides classes for working with dates and times. You can use the datetime class to represent both date and time information. from datetime import datetime now = datetime.now() # Current date and time print(now) Date and Time Objects: The datetime module includes date and time classes that allow you to work with just the date or time portion. DR.V.S.PRAKASH | V BCA 3
  • 4. String to Datetime Conversion: You can convert a string representing a date and time to a datetime object using the strptime method. date_str = "2023-10-24" datetime_obj = datetime.strptime(date_str, "%Y-%m-%d") Datetime to String Conversion: To convert a datetime object back to a string, you can use the strftime method. formatted_date = datetime_obj.strftime("%Y-%m-%d") DR.V.S.PRAKASH | V BCA 4
  • 8. TIME SERIES BASICS: Time series data consists of data points collected or recorded at successive, equally spaced time intervals. Common examples of time series data include stock prices, temperature measurements, and website traffic. Here are some fundamental concepts and tools for working with time series data in Python: Pandas: The Pandas library is a powerful tool for working with time series data. It provides data structures like DataFrame and Series that are ideal for organizing and analyzing time series data. import pandas as pd time_series_data = pd.Series([10, 20, 30, 40], index=pd.date_range(start='2023-10-01', periods=4, freq='D') DR.V.S.PRAKASH | V BCA 8
  • 9. Time Resampling: You can resample time series data to change the frequency of data points (e.g., from daily to monthly) using Pandas' resample method. Pandas dataframe.resample() function is primarily used for time series data. A time series is a series of data points indexed (or listed or graphed) in time order. Most commonly, a time series is a sequence taken at successive equally spaced points in time. It is a Convenience method for frequency conversion and resampling of time series. monthly_data = time_series_data.resample('M').mean() Plotting Time Series Data: Libraries like Matplotlib and Seaborn can be used to visualize time series data. import matplotlib.pyplot as plt time_series_data.plot() plt.xlabel("Date") plt.ylabel("Value") plt.show() DR.V.S.PRAKASH | V BCA 9
  • 10. Time Series Analysis: You can perform various time series analysis tasks, including trend analysis, seasonality detection, and forecasting, using tools like Statsmodels and Scikit-learn. from statsmodels.tsa.seasonal import seasonal_decompose decomposition = seasonal_decompose(time_series_data) trend = decomposition.trend seasonal = decomposition.seasonal Time series decomposition involves thinking of a series as a combination of level, trend, seasonality, and noise noise components. • Level: The average value in the series. • Trend: The increasing or decreasing value in the series. • Seasonality: The repeating short-term cycle in the series. • Noise: The random variation in the series. DR.V.S.PRAKASH | V BCA 10
  • 11. INDEXING AND SELECTION: Selecting by Index: You can access specific elements in a time series using index labels. import pandas as pd time_series_data = pd.Series([10, 20, 30, 40], index=pd.date_range(start='2023-10-01', periods=4, freq='D')) selected_data = time_series_data['2023-10-01'] Selecting by Slicing: Use slicing to select a range of data. selected_range = time_series_data['2023-10-01':'2023-10-03'] Subsetting by Conditions: You can subset time series data based on conditions using boolean indexing. subset = time_series_data[time_series_data > 20] DR.V.S.PRAKASH | V BCA 11
  • 12. Date Ranges and Frequencies: Date Ranges: You can create date ranges using Pandas' date_range function. This is useful for generating date index for time series data. date_range = pd.date_range(start='2023-10-01', end='2023-10-10', freq='D') Frequencies: You can specify various frequencies when creating date ranges. Common frequencies include 'D' (day), 'H' (hour), 'M' (month end), and more. hourly_range = pd.date_range(start='2023-10-01', periods=24, freq='H') monthly_range = pd.date_range(start='2023-01-01', end='2023-12-31', freq='M') Shifting Data: Shifting is a common operation when working with time series data, often used for calculating differences or creating lag features. Shift Data: You can shift the data forward or backward using the shift method. shifted_data = time_series_data.shift(periods=1) # Shift data one period forward Calculating Differences: To compute the difference between consecutive values, you can subtract the shifted series. DR.V.S.PRAKASH | V BCA 12
  • 13. SHIFTING DATA: Shifting data involves moving time series data forward or backward in time. This is useful for various time series analysis tasks. Shift Data: You can shift data using Pandas' shift method. The simplest call should have an argument periods (It defaults to 1) and it represents the number of shifts for the desired axis. And by default, it is shifting values vertically along the axis 0 . NaN will be filled for missing values introduced as a result of the shifting. import pandas as pd # Shifting data one period forward shifted_data = time_series_data.shift(periods=1) # Shifting data two periods backward shifted_data = time_series_data.shift(periods=-2) Calculating Differences: Shifting is often used to calculate the differences between consecutive values. # Calculate the difference between consecutive values DR.V.S.PRAKASH | V BCA 13
  • 14. Generating Date Ranges and Frequencies: Pandas provides powerful tools for generating date ranges with different frequencies. Date Ranges: Use the date_range function to create date ranges. date_range = pd.date_range(start='2023-01-01', end='2023-12-31', freq='D') # Daily frequency Frequencies: You can specify various frequencies such as 'D' (day), 'H' (hour), 'M' (month end), 'Y' (year end), and more when creating date ranges. hourly_range = pd.date_range(start='2023-01-01', periods=24, freq='H') monthly_range = pd.date_range(start='2023-01-01', end='2023-12-31', freq='M') DR.V.S.PRAKASH | V BCA 14
  • 15. Time Zone Handling: Pandas can handle time zones and convert between them. Setting Time Zone: time_series_data = time_series_data.tz_localize('UTC') # Set time zone to UTC Converting Time Zones: time_series_data = time_series_data.tz_convert('US/Eastern') # Convert to US Eastern Time Quarterly Period Frequencies: Quarterly periods can be generated with the "Q" frequency code. quarterly_range = pd.period_range(start='2023Q1', end='2023Q4', freq='Q') DR.V.S.PRAKASH | V BCA 15
  • 16. TIME SERIES ANALYSIS Time series analysis often involves various data manipulation tasks, including plotting, data munging, splicing data from multiple sources, decile and quartile analysis, and more. Let's explore these concepts and some sample applications in the context of time series analysis: Time Series Plotting: Plotting is crucial for visualizing time series data to identify patterns and trends. import matplotlib.pyplot as plt # Plot time series data time_series_data.plot() plt.xlabel("Date") plt.ylabel("Value") plt.title("Time Series Plot") plt.show() DR.V.S.PRAKASH | V BCA 16
  • 17. Data Munging: Data munging involves cleaning, transforming, and preparing data for analysis. In time series analysis, this might include handling missing values, resampling, or dealing with outliers. # Handling missing values time_series_data = time_series_data.fillna(method='ffill') # Resampling to a different frequency resampled_data = time_series_data.resample('W').mean() Splicing Together Data Sources: In some cases, you may need to combine time series data from multiple sources. import pandas as pd # Concatenating data from multiple sources combined_data = pd.concat([data_source1, data_source2]) Decile and Quartile Analysis: Decile and quartile analysis helps you understand the distribution of data. # Calculate quartiles quartiles = time_series_data.quantile([0.25, 0.5, 0.75]) # Calculate deciles deciles = time_series_data.quantile([i/10 for i in range(1, 10)]) DR.V.S.PRAKASH | V BCA 17
  • 18. Sample Applications: Stock Market Analysis: Analyzing stock price time series data for trends and predicting future stock prices. Temperature Forecasting: Analyzing historical temperature data to forecast future weather conditions. Demand Forecasting: Analyzing sales data to forecast future product demand. Future Contract Rolling: In financial time series analysis, rolling futures contracts is crucial to avoid jumps in time series data when contracts expire. # Rolling futures contracts in a DataFrame rolled_data = contract_rolling_function(time_series_data, window=10) Rolling Correlation and Linear Regression: Rolling correlation and regression are used to understand how the relationship between two time series changes over time. # Calculate rolling correlation between two time series rolling_corr = time_series_data1.rolling(window=30).corr(time_series_data2) # Calculate rolling linear regression between two time series rolling_regression = time_series_data1.rolling(window=30).apply(lambda x: your_lin DR.V.S.PRAKASH | V BCA 18
  • 19. DR.V.S.PRAKASH | V BCA 19 Data Munging: Data munging is a more general term that encompasses various data preparation tasks, including cleaning, structuring, and organizing data. It often involves dealing with missing data, handling outliers, and addressing issues like data format inconsistencies. Data munging can also include tasks such as data loading, data extraction, and basic data exploration. It is a broader term that doesn't specify a particular methodology or approach. Data Wrangling: Data wrangling is a subset of data munging that specifically refers to the process of cleaning, transforming, and structuring data for analysis. Data wrangling typically involves tasks like filtering, aggregating, joining, and reshaping data to create a dataset that is ready for analysis or machine learning. It is often associated with data preparation in the context of data analysis and is more focused on making data suitable for specific analytical tasks.