gurita Logo

Overview

  • Gurita: a command line data analytics and plotting tool
  • License
  • Installation
  • Example input data

General behaviour

  • Command line syntax
  • Input and output
  • Missing values
  • Plotting
  • List of commands
    • Reading and writing data from/to files
    • Plotting
    • Transformation and analysis
      • corr
      • cut
      • dropna
      • eval
      • filter
      • gmm (Gaussian mixture model)
      • groupby
      • head
        • Usage
        • Arguments
        • See also
        • Simple example
        • Getting help
        • Specifying the number of rows to select
      • kmeans
      • melt
      • normtest
      • outlier
      • pca
      • pivot
      • sample
      • sort
      • tail
      • unique
      • zscore
    • Summary information

Development

  • Contributing
  • Bug reports
  • Feature requests
gurita
  • »
  • List of commands »
  • head
  • View page source

head

Select a number of rows from the start (top) of the input data set, return the result as a new table.

Usage

gurita head [-h] [NUM]

Arguments

Argument

Description

Reference

-h

display help for this command

help

NUM

the number of rows to select

number of rows

See also

Compare to the tail command that returns rows from the end (bottom) of the data instead of the start.

Simple example

In the following document we assume the existence of an input file called example.csv that contains the following data (10 data rows and 1 heading row):

sepal_length,sepal_width,petal_length,petal_width,species
5.1,3.5,1.4,0.2,setosa
4.9,3.0,1.4,0.2,setosa
4.7,3.2,1.3,0.2,setosa
4.6,3.1,1.5,0.2,setosa
5.0,3.6,1.4,0.2,setosa
5.4,3.9,1.7,0.4,setosa
4.6,3.4,1.4,0.3,setosa
5.0,3.4,1.5,0.2,setosa
4.4,2.9,1.4,0.2,setosa
4.9,3.1,1.5,0.1,setosa

Select the first 5 rows from example.csv:

gurita head 5 < example.csv

The output of the above command is:

sepal_length,sepal_width,petal_length,petal_width,species
5.1,3.5,1.4,0.2,setosa
4.9,3.0,1.4,0.2,setosa
4.7,3.2,1.3,0.2,setosa
4.6,3.1,1.5,0.2,setosa
5.0,3.6,1.4,0.2,setosa

Note that there are 5 data rows in the above result plus one header row.

The head command returns a data set as its output, so it can be combined with other commands in a chain using the + operator.

For example the following command uses head to select the first 5 rows from the input data and then uses tail to select the last 3 rows from the first 5. The net result is that rows 3,4,5 (counting from 1) of the original data are returned.

gurita head 5 + tail 3 < example.csv
sepal_length,sepal_width,petal_length,petal_width,species
4.7,3.2,1.3,0.2,setosa
4.6,3.1,1.5,0.2,setosa
5.0,3.6,1.4,0.2,setosa

Getting help

The full set of command line arguments for head can be obtained with the -h or --help arguments:

gurita head -h

Specifying the number of rows to select

The head command takes exactly one argument, an integer NUM.

  • If NUM > 0, rows will be selected from the start (top) of the data. If NUM is greater than or equal to the number of rows in the data then the entire input data will be returned as the result.

  • If NUM = 0, the result will be an empty data set.

  • If NUM < 0, select all rows except the last NUM rows of the data. If NUM is greater than or equal to the number of rows in the data then the result will be an empty data set.

Select the first 1 rows from example.csv:

gurita head 1 < example.csv

The output of the above command is:

sepal_length,sepal_width,petal_length,petal_width,species
5.1,3.5,1.4,0.2,setosa

Select all but the last 3 lines from example.csv. Note that this yields the first 7 rows of the data because there are 10 rows in total and the last 3 are removed.

gurita head -3 < example.csv

The output of the above command is:

sepal_length,sepal_width,petal_length,petal_width,species
5.1,3.5,1.4,0.2,setosa
4.9,3.0,1.4,0.2,setosa
4.7,3.2,1.3,0.2,setosa
4.6,3.1,1.5,0.2,setosa
5.0,3.6,1.4,0.2,setosa
5.4,3.9,1.7,0.4,setosa
4.6,3.4,1.4,0.3,setosa
Previous Next

Built with Sphinx using a theme provided by Read the Docs.