Catmandu::Stat(3pm)

✨ Catmandu::Stat ✨

okay bestie, welcome to Catmandu::Stat β€” it's the part of Catmandu that does ✨statistics✨, like literally working with statistical data. that's the whole vibe. Catmandu modules for working with statistical data. slay. πŸ’…

This page is from the User Contributed Perl Documentation, and honestly? she's giving main character energy. πŸŽ€


🌸 SYNOPSIS 🌸

here's the tea, straight up:

# Calculate statistics on the availabity of the ISBN fields in the dataset
cat data.json | catmandu convert JSON to Stat --fields isbn

# Preprocess data and calculate statistics
catmandu convert MARC to Stat --fix 'marc_map(020a,isbn)' --fields isbn < data.mrc

# Or in fix files

# Calculate the mean of foo. E.g. foo => [1,2,3,4]
stat_mean(foo)  # foo => '2.5'

# Calculate the median of foo. E.g. foo => [1,2,3,4]
stat_median(foo)  # foo => '2.5'

# Calculate the standard deviation of foo. E.g. foo => [1,2,3,4]
stat_stddev(foo)  # foo => '1.12'

# Calculate the variance of foo. E.g. foo => [1,2,3,4]
stat_variance(foo)  # foo => '1.25'
heads up: that typo in the comment says availabity and no i will not be fixing it, we keep every detail in this house. periodt. πŸ’–

πŸ‘‘ MODULES πŸ‘‘

the whole squad, right here:

  • Catmandu::Exporter::Stat
  • Catmandu::Fix::stat_mean
  • Catmandu::Fix::stat_median
  • Catmandu::Fix::stat_stddev
  • Catmandu::Fix::stat_variance

πŸ¦‹ EXAMPLES πŸ¦‹

okay so the Catmandu::Stat distribution ships with a CSV file about the Sacramento crime rate in January 2006, called t/SacramentocrimeJanuary2006.csv, and you can also grab it at http://samplecsvs.s3.amazonaws.com/SacramentocrimeJanuary2006.csv πŸ’œ

wanna peek at the stats on the fields in that file? type this:

$ catmandu convert CSV to Stat < t/SacramentocrimeJanuary2006.csv

| name          | count | zeros | zeros% | min | max | mean | variance | stdev | uniq~ | uniq% | entropy   |
|---------------|-------|-------|--------|-----|-----|------|----------|-------|-------|-------|-----------|
| #             | 7584  |       |        |     |     |      |          |       |       |       |           |
| address       | 7584  | 0     | 0.0    | 1   | 1   | 1    | 0.0      | 0.0   | 5425  | 71.5  | 12.4/12.4 |
| beat          | 7584  | 0     | 0.0    | 1   | 1   | 1    | 0.0      | 0.0   | 20    | 0.3   | 4.3/12.9  |
| cdatetime     | 7584  | 0     | 0.0    | 1   | 1   | 1    | 0.0      | 0.0   | 5071  | 66.9  | 12.3/12.3 |
| crimedescr    | 7584  | 0     | 0.0    | 1   | 1   | 1    | 0.0      | 0.0   | 305   | 4.0   | 5.6/12.6  |
| district      | 7584  | 0     | 0.0    | 1   | 1   | 1    | 0.0      | 0.0   | 6     | 0.1   | 2.6/12.9  |
| grid          | 7584  | 0     | 0.0    | 1   | 1   | 1    | 0.0      | 0.0   | 537   | 7.1   | 7.8/9.9   |
| latitude      | 7584  | 0     | 0.0    | 1   | 1   | 1    | 0.0      | 0.0   | 5288  | 69.7  | 12.4/12.4 |
| longitude     | 7584  | 0     | 0.0    | 1   | 1   | 1    | 0.0      | 0.0   | 5295  | 69.8  | 12.4/12.4 |
| ucr_ncic_code | 7584  | 0     | 0.0    | 1   | 1   | 1    | 0.0      | 0.0   | 88    | 1.2   | 4.1/12.9  |

so what is this table even telling us?? πŸ‘€ the file has 7584 rows, and literally all the fields from "address" to "ucr_ncic_code" contain values. each field has only one value (there are no arrays available in the CSV file, so that's just how it is). there are 5492 unique addresses in the CSV file. and the "district" field has the lowest entropy β€” most of its values are shared among many rows. iconic lowkey. 🫢


πŸ”₯ SEE ALSO πŸ”₯

  • Catmandu
  • Catmandu::Breaker

πŸ’– AUTHOR πŸ’–

Patrick Hochstenbach, "<patrick.hochstenbach at ugent.be>" β€” thank u king, we appreciate u 🫢✨


This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information. πŸ’œ


and that's a wrap bestie!! πŸŽ€ this page came to you via perl v5.36.0, dated 2023-02-06 β€” the day this iconic lil manpage got its timestamp, and we are obsessed. go forth and calculate ur stats, no cap. πŸ’…βœ¨πŸ’–

πŸ“¦ where this page comes from