Reading time series from disk
After storing a time series in a file, we need to write the necessary Python code to read it and put it in a Python variable of some type. This section will teach you exactly that. The read_ts.py
script contains the following code:
#!/usr/bin/env python3 import pandas as pd import numpy as np import sys def main(): filename = sys.argv[1] ts1Temp = pd.read_csv(filename, header = None) # Convert to NParray ta = ts1Temp.to_numpy() ta = ta.reshape(len(ta)) print("Length:", len(ta)) if __name__ == '__main__': main()
After reading the time series, read_ts.py
prints the number of elements in the time series:
$ ./read_ts.py ts2 Length: 50
The pd.read_csv()
function reads a plain text file that uses the CSV format – in our case, each value is on its own line, so there should be no issues with separating values that reside on the same line. The pd.read_csv()
function is...