Skip to main content

csv_manager

This is a python module that features three simple classes for reading (class Reader), plotting (class Plotter, using Matplotlib with Latex rendering enabled) for the plots) and managing (class Database) CSV files and also a method for writing CSVs.

By using this module, the user avoids the cumbersome repetition of coding a csv reader using the csv python library then making the data in a readable structure for plt.plot(...).

Simple single graph example

from csv_manager import Plotter, DataFile
# Plotter inherits the class Reader

plotter = Plotter()
# Number of rows and columns for plt.sublots

datafile = DataFile('data_file_1.csv')

datafile.get_column_names('dataset1')
# returns the list of column names of the file `data_file_1.csv`

######################################################

plotter.plot(datafile, 'time', 'position', label='position $x(t)$', color='red', linestyle=':')
# Starting from " label='save' [...]" the arguments are the **kwargs in https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html
plotter.plot(datafile, 'time', 'speed', label='speed $v(t)$', color='blue', linestyle='--')

plotter.plot(datafile, 'time', 'position + sqrt(2/10 * speed)', 0, 1, label='dummy curve from expression')
# Mathematical expressions involving column names can be used

plotter.plot_data([0, 1, 2], [0, 1, 2], label='dummy data')

plotter.set(xlabel='Time ', ylabel='Position')
# the options that can be set are the **kwargs in https://matplotlib.org/api/axes_api.html

plotter.show()

The file data_file_1.csv can be the followin (Note that the default column separator is a single space):

time position speed
0 0 0
1 5 3
2 20 3.6
3 45 2
4 80 5
5 125 8
6 180 9
7 245 10
8 320 9.2
9 405 8
10 500 7

Using Database

If you have a folder with lots of CSV files and find it too cumbersome to find the correct ones to plot or read. The class Databse is made for you!

Requirements:

  • Have all your CSV files in a folder (still works if they are in a subfolder of that folder)
  • One of the following (or both):
    • Follow a specific naming scheme on your CSV files: filename|var1=val1|var2=val2|...|varN=valN.csv where | is a separator that can be different (any string of characters).
    • Have sim_setting_name and sim_setting_value columns in your datafile (names can be changed), that contains the variables that define the simulation settings, e.g.:
      time speed sim_setting_name sim_setting_value
      0 1 wind_speed 2.4
      1 2 temp 25
      2 4
      3 5
      ...
      
Filtering

Then, what you can do is to create a Database instance with the folder path, and then you can use its method filter_datafiles:

def filter_datafiles(self, file_name_base: str, filter_dict : dict) -> List[DataFile]:

where:

  • file_name_base is a string that the file should contain in its filename (the text before the start of the variable definitions)
  • filter_dict is a dictionary that contains (key, val) pairs, both strings, that correspond to varN=valN in the csv files you are looking for.

And this method will return all the files that match your filters. The retrieve a single datafile interactively, you can use the file_selection_prompt method from Database.

Dependencies:

  • Python Matplotlib
  • Python py_expression_eval, can be installed with pip install py_expression_eval
  • Latex distribution installed in your computer, can be deactivated in csv_plotter.py by changing the following line plt.rcParams['text.usetex'] = True to plt.rcParams['text.usetex'] = False

Release files for csv-manager 0.11.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for csv-manager 0.11.9
File Size Uploaded
csv_manager-0.11.9.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for csv-manager 0.11.9
File Interpreter ABI Platform
csv_manager-0.11.9-py3-none-any.whl Python 3 none any Details

Total release size: 27.0 kB

Release files / csv_manager-0.11.9.tar.gz

Download URL csv_manager-0.11.9.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
42214010725b045ebfd2e1a72efb888a14dbe980fcd9a4c59f18618e4aebc58c
BLAKE2b-256 checksum
How to use checksums
1c5a7c3868e48eafbe57ce8a1702b9f02b7cb97e6c31c065b942b4eac3c34f1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release files / csv_manager-0.11.9-py3-none-any.whl

Download URL csv_manager-0.11.9-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18a0f3f23744f95e2fb87ab3ed9455dd357e7e4d44fc7d1b0e470795f7abd80c
BLAKE2b-256 checksum
How to use checksums
41fc6d87e5fced0b2b5d50466c91ba6c24bc378fb051a9cf5a2da17a7c546848
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.11.9 This release

2 release files

0.11.8

2 release files

0.11.7

2 release files

0.11.6

2 release files

0.11.5

2 release files

0.9

2 release files

0.8

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page