0% found this document useful (0 votes)
14 views24 pages

Time Series

Uploaded by

hanyeelovesgod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views24 pages

Time Series

Uploaded by

hanyeelovesgod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

035.

001 Spring, 2024

Digital Computer Concept and Practice


File import/export, Time-series analysis (1)

Soohyun Yang

College of Engineering
Department of Civil and Environmental Engineering
Overview
By participating in today’s lecture, you should be able to understand
and apply the following content:

 to import a file into, or export a file from, your program


 to get familiar with using a module for work with time-series data
Why to read & write files in programming?
 Aims to make your programs more applicable, usable, and stable.
 An incredible amount of data & info is available.
=> Useful in analyzing data, modifying info, and saving results of the analysis
A generalized approach to work with files
 Create a separate sub-folder, such as named ‘DATA’
 Save a file with data into the sub-folder
 Define (1) a directory containing the data file,
(2) the data file’s name and extension.
 Use the open() function => A file object is created
• Open a file in read mode (‘r’), write mode (‘w’), or append mode (‘a’).
• The read mode is a default option.
 Use the read() function for the file object
 Use the write() function to save info to the file object
Reading a file into memory
>> Note : The read() function returns
the entire contents of the file
into a single string.
Appending info to an existing file
>> Note : The ‘a’ argument opens the file
for appending rather than writing
over the existing file.
Appending info to an existing file (con’t)
>> Note : You can append varying variables
to a file through a loop!
Writing info to a new file
>> Note : If a file exists, opening it
in ‘w’ mode will erase the file
before returning the file object.
Otherwise, Python automatically
create a new one.
How can we particularly work with ‘.csv’ files?
 Create a separate sub-folder, such as named ‘DATA’
 Save a file with data into the sub-folder
 Define (1) a directory containing the data file,
(2) the data file’s name and extension.

 Create a separate sub-folder, called ‘EXPORT’


 Use the pandas module (as pd)
• pd.read_csv(import_filename.csv)
=> Import the contents in a csv file as a DataFrame-type (df)
• df.to_csv(export_filename.csv)
=> Export a DataFrame-type variable to a csv file
Let’s give it a try! - Import

Column with time info is


saved as the object-type.
Let’s give it a try! – Import (2)

Convert to
the datetime-type!
Let’s give it a try! – Formatting & Plotting
… Continued codes
Let’s give it a try! – Formatting & Plotting (2)
… Continued codes
Let’s give it a try! - Export
Time-series data exists in almost everywhere
 TS : A set of ordered observations on a quantitative characteristic
of an individual or collective phenomenon taken at different points
in time.
Time-series patterns vary in space

(Botter et al., 2013)


Time-series can be dependent each other

(Musolff et al., 2017)


“Future” time-series is simulated
C) Total Final Energy Demand

(Riahi et al., 2017; IPCC AR6)


Individual Project :
Let’s assign ‘station_id’ & ‘variable_id’ (random#)
 Daily observation data
 15 stations located in South Korea
 5 meteorological variables
• Air Temperature [°C]
• Precipitation [mm]
• Wind Speed [m/s]
• Relative Humidity [%]
• Vapor Pressure [hPa]
Sites for the individual project

Varb_id varb_names meaning Unit


1 Temp Temperature Temp_degC
2 Prep Precipitation Prep_mm
3 WS Wind Speed WS_mps
4 RH Relative Humidity RH_prct
5 VP Vapor Pressure VP_hPa
Take-home points (THPs)
…
…
…
…

You might also like