Skip to content

pylhc/tfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TFS-Pandas

Cron Testing Code Climate coverage Code Climate maintainability (percentage)

GitHub release PyPI Version Conda-forge Version DOI

This package provides reading and writing functionality for Table Format System (TFS) files. Files are read into a TfsDataFrame, a class built on top of the famous pandas.DataFrame, which in addition to the normal behavior attaches a dictionary of headers to the DataFrame.

See the API documentation for details.

Installing

Installation is easily done via pip:

python -m pip install tfs-pandas

One can also install in a conda/mamba environment via the conda-forge channel with:

conda install -c conda-forge tfs-pandas

Example Usage

The package is imported as tfs, and exports top-level functions for reading and writing:

import tfs

# Loading a TFS file is simple
data_frame = tfs.read("path_to_input.tfs", index="index_column")

# You can access and modify the headers with the .headers attribute
useful_variable = data_frame.headers["SOME_KEY"]
data_frame.headers["NEW_KEY"] = some_variable

# Manipulate data as you do with pandas DataFrames
data_frame["NEWCOL"] = data_frame.COL_A * data_frame.COL_B

# You can check the validity of a TfsDataFrame, and choose the behavior in case of errors
tfs.frame.validate(data_frame, non_unique_behavior="raise")  # or choose "warn"

# Writing out to disk is simple too
tfs.write("path_to_output.tfs", data_frame, save_index="index_column")

Reading and writing compressed files is also supported, and done automatically based on the provided file extension:

import tfs

# Reading a compressed file is simple, compression format is inferred
df = tfs.read("path_to_input.tfs.gz")

# When writing choose the compression format by providing the appropriate file extension
tfs.write("path_to_output.tfs.bz2", df)
tfs.write("path_to_output.tfs.zip", df)

License

This project is licensed under the MIT License - see the LICENSE file for details.