|
1 | 1 | # TFS-Pandas |
| 2 | + |
2 | 3 | [](https://github.com/pylhc/tfs/actions?query=workflow%3A%22Cron+Testing%22) |
3 | 4 | [](https://codeclimate.com/github/pylhc/tfs) |
4 | 5 | [](https://codeclimate.com/github/pylhc/tfs) |
5 | 6 | [](https://github.com/pylhc/tfs/) |
6 | 7 | [](https://github.com/pylhc/tfs/) |
7 | 8 | [](https://doi.org/10.5281/zenodo.5070986) |
8 | 9 |
|
9 | | -This package provides reading and writing functionality for **table format system (tfs)** files. |
10 | | - |
11 | | -## Getting Started |
12 | | - |
13 | | -### Prerequisites |
| 10 | +This package provides reading and writing functionality for [**table format system (tfs)** files](http://mad.web.cern.ch/mad/madx.old/Introduction/tfs.html). |
| 11 | +Files are read into a `TfsDataFrame`, a class built on top of the famous `pandas.DataFrame`, which in addition to the normal behaviour attaches an `OrderedDict` of headers to the `DataFrame`. |
14 | 12 |
|
15 | | -The package depends heavily on `pandas` and also on `numpy`, so these packages need |
16 | | -to be installed in your python environment. |
| 13 | +## Installing |
17 | 14 |
|
18 | | -### Installing |
19 | | - |
20 | | -Installation is easily done via `pip`. The package is then used as `tfs`. |
| 15 | +Installation is easily done via `pip`: |
21 | 16 |
|
22 | 17 | ``` |
23 | 18 | pip install tfs-pandas |
24 | 19 | ``` |
25 | 20 |
|
26 | | -Example: |
| 21 | +## Example Usage |
27 | 22 |
|
| 23 | + The package is imported as `tfs`, and exports top-level functions for reading and writing: |
28 | 24 | ```python |
29 | 25 | import tfs |
30 | 26 |
|
31 | | -data_frame = tfs.read('path_to_input.tfs', index="index_column") |
32 | | -tfs.write('path_to_output.tfs', data_frame, save_index="index_column") |
33 | | -``` |
34 | | -## Description |
| 27 | +# Loading a TFS file is simple |
| 28 | +data_frame = tfs.read("path_to_input.tfs", index="index_column") |
35 | 29 |
|
36 | | -Reading and writing capabilities for [tfs-files](http://mad.web.cern.ch/mad/madx.old/Introduction/tfs.html) |
37 | | -are provided by this package. The files are read into special `pandas` `Dataframes`, called `TfsDataFrames`, |
38 | | -which in addition to the normal behaviour attach an `OrderedDict` of headers to the `DataFrame`. |
| 30 | +# You can access and modify the headers with the .headers attribute |
| 31 | +useful_variable = data_frame.headers["SOME_KEY"] |
| 32 | +data_frame.headers["NEW_KEY"] = some_variable |
39 | 33 |
|
40 | | -### Changelog |
| 34 | +# Manipulate data as you do with pandas DataFrames |
| 35 | +data_frame["NEWCOL"] = data_frame.COL_A * data_frame.COL_B |
41 | 36 |
|
42 | | -See the [CHANGELOG](CHANGELOG.md) file. |
| 37 | +# You can check the validity of a TfsDataFrame, and choose the behavior in case of errors |
| 38 | +tfs.frame.validate(data_frame, non_unique_behavior="raise") # or choose "warn" |
43 | 39 |
|
44 | | -## Known Issues |
45 | | - |
46 | | -- Creating a new `DataFrame` by combining multiple `TfsDataFrame`, |
47 | | -for example via `pandas.DataFrame.append()` or `pandas.concat()`, |
48 | | -will convert the `TfsDataFrame` back to a `DataFrame` and lose therefore the headers. |
49 | | - |
50 | | -## Authors |
51 | | - |
52 | | -* **Jaime** - [jaimecp89](https://github.com/jaimecp89) |
53 | | -* **Lukáš** - [lmalina](https://github.com/lmalina) |
54 | | -* **Josch** - [JoschD](https://github.com/JoschD) |
55 | | -* **Felix** - [fsoubelet](https://github.com/fsoubelet) |
56 | | -* **pyLHC/OMC-Team** - *Working Group* - [pyLHC](https://github.com/orgs/pylhc/teams/omc-team) |
| 40 | +# Writing out to disk is simple too |
| 41 | +tfs.write("path_to_output.tfs", data_frame, save_index="index_column") |
| 42 | +``` |
57 | 43 |
|
| 44 | +It also provides some tools to validate and manipulate `TfsDataFrames` and their headers; or lazily manage a collection of TFS files. |
| 45 | +See the [API documentation](https://pylhc.github.io/tfs/) for details. |
58 | 46 |
|
59 | 47 | ## License |
60 | 48 |
|
61 | | -This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 49 | +This project is licensed under the `MIT License` - see the [LICENSE](LICENSE) file for details. |
0 commit comments