Skip to main content

This file is part of datamatrix.

Project description

Python DataMatrix

An intuitive, Pythonic way to work with tabular data.

Sebastiaan Mathôt
Copyright 2015-2024
https://pydatamatrix.eu/

Publish to PyPi

Tests

Contents

About

DataMatrix is an intuitive Python library for working with column-based, time-series, and multidimensional data. It's a light-weight and easy-to-use alternative to pandas.

DataMatrix is also one of the core libraries of OpenSesame, a graphical experiment builder for the social sciences, and Rapunzel, a modern code editor for numerical computing with Python and R.

Features

  • An intuitive syntax that makes your code easy to read
  • Mix tabular data with time series and multidimensional data in a single data structure
  • Support for large data by intelligent (and automatic) offloading of data to disk when memory is running low
  • Advanced memoization (caching)
  • Requires only the Python standard libraries (but you can use numpy to improve performance)
  • Compatible with your favorite data-science libraries:
    • seaborn and matplotlib for plotting
    • scipy, statsmodels, and pingouin for statistics
    • mne for analysis of electroencephalographic (EEG) and magnetoencephalographic (MEG) data
    • Convert to and from pandas.DataFrame
    • Looks pretty inside a Jupyter Notebook

Ultra-short cheat sheet

from datamatrix import DataMatrix, io
# Read a DataMatrix from file
dm = io.readtxt('data.csv')
# Create a new DataMatrix
dm = DataMatrix(length=5)
# The first two rows
print(dm[:2])
# Create a new column and initialize it with the Fibonacci series
dm.fibonacci = 0, 1, 1, 2, 3
# You can also specify column names as if they are dict keys
dm['fibonacci'] = 0, 1, 1, 2, 3
# Remove 0 and 3 with a simple selection
dm = (dm.fibonacci > 0) & (dm.fibonacci < 3)
# Get a list of indices that match certain criteria
print(dm[(dm.fibonacci > 0) & (dm.fibonacci < 3)])
# Select 1, 1, and 2 by matching any of the values in a set
dm = dm.fibonacci == {1, 2}
# Select all odd numbers with a lambda expression
dm = dm.fibonacci == (lambda x: x % 2)
# Change all 1s to -1
dm.fibonacci[dm.fibonacci == 1] = -1
# The first two cells from the fibonacci column
print(dm.fibonacci[:2])
# Column mean
print(dm.fibonacci[...])
# Multiply all fibonacci cells by 2
dm.fibonacci_times_two = dm.fibonacci * 2
# Loop through all rows
for row in dm:
    print(row.fibonacci) # get the fibonacci cell from the row
# Loop through all columns
for colname, col in dm.columns:
    for cell in col: # Loop through all cells in the column
        print(cell) # do something with the cell
# Or just see which columns exist
print(dm.column_names)

Documentation

The basic documentation (including function and module references) is hosted on https://pydatamatrix.eu/. Additional tutorials can be found in the data-science course on https://pythontutorials.eu/.

Dependencies

DataMatrix requires only the Python standard library. That is, you can use it without installing any additional Python packages (although the pip and conda packages install some of the optional dependencies by default). Python 3.7 and higher are supported.

The following packages are required for extra functionality:

  • numpy and scipy for using the FloatColumn, IntColumn, SeriesColumn, MultiDimensionalColumn objects
  • pandas for conversion to and from pandas.DataFrame
  • mne for conversion to and from mne.Epochs and mne.TFR
  • fastnumbers for improved performance
  • prettytable for creating a text representation of a DataMatrix (e.g. to print it out)
  • openpyxl for reading and writing .xlsx files
  • json_tricks for hashing, serialization to and from json, and memoization (caching)
  • tomlkit for reading configuration from pyproject.toml
  • psutil for dynamic loading of large data

Installation

PyPi

pip install datamatrix

Historical note: The DataMatrix project used to correspond to another package of the same name, which was discontinued in 2010. If you want to install this package, you can do still do so by providing an explicit version (0.9 is the latest version of this package), as shown below. With thanks to dennogumi.org for handing over this project's entry on PyPi, thus avoiding much unnecessary confusion!

# Doesn't install datamatrix but a previous package by the same name!
pip install datamatrix==0.9

Anaconda

conda install datamatrix -c conda-forge

Ubuntu

sudo add-apt-repository ppa:smathot/cogscinl  # for stable releases
sudo add-apt-repository ppa:smathot/rapunzel  # for development releases
sudo apt-get update
sudo apt install python3-datamatrix

License

python-datamatrix is licensed under the GNU General Public License v3.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datamatrix-1.0.14.tar.gz (78.5 kB view details)

Uploaded Source

Built Distribution

datamatrix-1.0.14-py3-none-any.whl (108.1 kB view details)

Uploaded Python 3

File details

Details for the file datamatrix-1.0.14.tar.gz.

File metadata

  • Download URL: datamatrix-1.0.14.tar.gz
  • Upload date:
  • Size: 78.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for datamatrix-1.0.14.tar.gz
Algorithm Hash digest
SHA256 34df503ef9c2dc9c05316a2c65d88c611e54b6d08722b81e95885836f64dc490
MD5 c8e9bdf5d282795af40ec1a03a926870
BLAKE2b-256 9450cbcd655f6dba2909598afcee2583725c782aa15c7e98b58459cd474c9a3c

See more details on using hashes here.

File details

Details for the file datamatrix-1.0.14-py3-none-any.whl.

File metadata

  • Download URL: datamatrix-1.0.14-py3-none-any.whl
  • Upload date:
  • Size: 108.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for datamatrix-1.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 885ffeb53bd8cca739b640d0aeb16a917240c1d8809f0d92443c04ddc035ab5c
MD5 0db3510ce92087bde5dc01ce7ead40b1
BLAKE2b-256 ed81e0cc1e7f5bc3335fc44fb255623f384dc0bed28f75273c2a9b325ff94d28

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page