Preparing time series data in old fixed width format with python

Hydsys Format

The definition of the hydrograph text file is defined here:

  • first column is station “A8” means it is a text of 8 characters width, and we need to pad on the right side with spaces if the name is less than 8 letters long. Therefore we need to format it as “8CAM01__ “ (_ means it is a space).
  • second column defines the type of the variable and it is a float number of 7 characters long, “_140.00”, with 1 space to pad on the left, and the 140.00 means it is a hydrograph instead of rainfall
  • the next few date columns are straightforward, just using this format, “YYYYMMDDHHMM”, “201309071140” is “2013 Sep 07 11:40”
  • the last column is the value, it is a float number of 12 characters long

Python script

As shown below, the heart of the python script is to implement the definition.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store