Reading and writing in feather format

Overview:

  • The primary reason for the existence of Feather is to have a data format using which data frames can be exchanged between Python and R.
  • Feather is a binary data format.
  • Using feather enables faster I/O speeds and less memory. However, since it is an evolving format it is recommended to use it for quick loading and transformation related data processing rather than using it as a long term storage.
  • The example Python program creates a pandas dataframe object from a Python dictionary. The dataframe is persisted into a disk file in Feather format by calling the to_feather() method on the dataframe instance.
  • The contents of the disk file is read back by calling the method read_feather() method of the pandas module and printed onto the console.

Example:

import pandas as pd

import feather

 

pingInfoFilePath = "./serverpings.ftr";

pingInfo    = {"servername": ["svr_et_1","svr_et_2","svr_wt_1","svr_wt_2","svr_nr_1","svr_nr_2","svr_st_1","svr_st_2"],

                "lastping":["12.20.15.122","12.20.11.395", "12.20.12.836","12.20.16.769","12.20.17.193","12.20.18.416","11.59.55.913","12.20.14.811"],

                "roundtriptime":[300, 400, 0, 200, 100, 500, 350, 0],

                "status":["PASS","PASS","FAIL","PASS","PASS","PASS","PASS","FAIL"]};

           

dataFrame   = pd.DataFrame(data=pingInfo);

dataFrame.to_feather(pingInfoFilePath);

 

readFrame = pd.read_feather(pingInfoFilePath, columns=None, use_threads=True);

print(readFrame);

 

Output:

  servername      lastping  roundtriptime status

0   svr_et_1  12.20.15.122            300   PASS

1   svr_et_2  12.20.11.395            400   PASS

2   svr_wt_1  12.20.12.836              0   FAIL

3   svr_wt_2  12.20.16.769            200   PASS

4   svr_nr_1  12.20.17.193            100   PASS

5   svr_nr_2  12.20.18.416            500   PASS

6   svr_st_1  11.59.55.913            350   PASS

7   svr_st_2  12.20.14.811              0   FAIL

 


Copyright 2024 © pythontic.com