Skip to main content

Data import

Codehooks supports import of large data sets from CSV and JSON files.

In this example we'll use a dataset from Kaggle machine learning data site. The data contains 5 years of stock trading results with 619040 records.

You'll find the dataset here https://www.kaggle.com/datasets/camnugent/sandp500

After downloading the data we use the CLI to import the data file to a collection stocks.

CLI command
coho import -c stocks -f ~/Downloads/all_stocks_5yr.csv                    
Codehooks data import [==============================] 178673/bps 100% 0.0s

Finished import of 619040 objects

We can inspect that the dataset is imported correctly with the coho query command.

CLI command
coho query stocks --limit 2
output
{
date: '2013-03-14',
open: 15.98,
high: 16.36,
low: 15.93,
close: 16.25,
volume: 8383300,
Name: 'AAL',
_id: '18007b5f8d7-000mnf5l50qd7a'
}
{
date: '2013-03-07',
open: 14.7,
high: 14.93,
low: 14.5,
close: 14.82,
volume: 9125300,
Name: 'AAL',
_id: '18007b5f8d7-058mo6lu276dq0'
}

We can also perform complex queries on datasets.

E.g. find all Google trades that closed above $110.

CLI command
coho query stocks 'Name=GOOG&close>1100'
output
{
date: '2018-01-23',
open: 1159.85,
high: 1171.63,
low: 1158.75,
close: 1169.97,
volume: 1333056,
Name: 'GOOG',
_id: '640f60e2b4fdc00015c4280f'
}
{
date: '2018-01-31',
open: 1170.57,
high: 1173,
low: 1159.13,
close: 1169.94,
volume: 1538688,
Name: 'GOOG',
_id: '640f60f2b4fdc00015c42811'
}
...
tip

Use the coho query --table option to display data in tabular form. Use the --raw option to output data for further processing.

CLI command
coho query stocks --limit 2 --table
┌───────────┬───────────┬───────────┬───────────┬───────────┬───────────┬───────────┬───────────┐
│ date │ open │ high │ low │ close │ volume │ Name │ _id │
├───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ 2013-03-… │ 15.98 │ 16.36 │ 15.93 │ 16.25 │ 8383300 │ AAL │ 18007b5f… │
├───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ 2013-03-… │ 14.7 │ 14.93 │ 14.5 │ 14.82 │ 9125300 │ AAL │ 18007b5f… │
└───────────┴───────────┴───────────┴───────────┴───────────┴───────────┴───────────┴───────────┘