Visitar URL original
DataFrame
dataframe-3.8.0.0: A fast, safe, and intuitive DataFrame library.
Safe HaskellNone
LanguageHaskell2010

DataFrame

Description

Batteries-included entry point re-exporting the common pieces for GHCi.

Synopsis

Core data structures

Operator symbols.

Display operations

data DisplayOptions #

Constructors

DisplayOptions 

Fields

defaultDisplayOptions :: DisplayOptions #

Terminal defaults: 10 rows plus the standard column and cell caps.

display :: DisplayOptions -> DataFrame -> IO () #

Render a DataFrame to stdout according to DisplayOptions.

Core dataframe operations

Types

data SchemaType where #

A runtime tag for a column’s element type.

Constructors

SType :: forall a. (Columnable a, Read a) => Proxy a -> SchemaType

Constructor carrying a Proxy of the element type.

Instances

Instances details
Show SchemaType

Show the underlying element type using typeRep.

Instance details

Defined in DataFrame.Internal.Schema

Eq SchemaType

Two SchemaTypes are equal iff their element types are the same.

Instance details

Defined in DataFrame.Internal.Schema

schemaType :: (Columnable a, Read a) => SchemaType #

Construct a SchemaType for the given a.

makeSchema :: [(Text, SchemaType)] -> Schema #

Construct a Schema from a list of (columnName, schemaType) pairs.

deriveSchemaValues :: Name -> DecsQ #

Derive an untyped Schema value and per-column accessors from a record.

I/O

data ReadOptions #

CSV read parameters.

Constructors

ReadOptions 

Fields

data TypeSpec #

How a reader decides each column's type.

Constructors

InferFromSample Int

Infer each column's type from the first n rows.

SpecifyTypes [(Text, SchemaType)] TypeSpec

Pin the listed columns to their given types, with a fallback.

NoInference

Every column is read as Text, no inference at all.

data HeaderSpec #

Where a reader's column names come from.

Constructors

NoHeader 
UseFirstRow

Take names from the first row (the default).

ProvideNames [Text]

Name the leading columns; any beyond the given list are numbered.

Instances

Instances details
Show HeaderSpec 
Instance details

Defined in DataFrame.IO.CSV.Internal.Options

Eq HeaderSpec 
Instance details

Defined in DataFrame.IO.CSV.Internal.Options

defaultReadOptions :: ReadOptions #

The default ReadOptions: infer from 100 rows, header row, all data.

readCsv :: FilePath -> IO DataFrame #

Read a CSV file from a path into a dataframe.

readCsvWithSchema :: Schema -> FilePath -> IO DataFrame #

Read a CSV, coercing columns to the types declared in a Schema.

readCsvWithOpts :: ReadOptions -> FilePath -> IO DataFrame #

Read a CSV file from a path using the given ReadOptions.

readTsv :: FilePath -> IO DataFrame #

Read a tab-separated file into a dataframe.

readSeparated :: ReadOptions -> FilePath -> IO DataFrame #

Read a text file with a chosen delimiter into a dataframe.

writeCsv :: FilePath -> DataFrame -> IO () #

Write a dataframe to a comma-separated file.

writeSeparated #

Arguments

:: Char

Separator

-> FilePath

Path to write to

-> DataFrame 
-> IO () 

Write a dataframe to a file using the given field separator.

fromCsv :: String -> IO (Either String DataFrame) #

Parse a CSV string into a DataFrame using default options.

fromCsvBytes :: ByteString -> IO DataFrame #

Parse a lazy ByteString of CSV data using default options.

data ParquetReadOptions #

Options for reading Parquet data.

Constructors

ParquetReadOptions 

Fields

Instances

Instances details
Show ParquetReadOptions 
Instance details

Defined in DataFrame.IO.Parquet

defaultParquetReadOptions :: ParquetReadOptions #

Default Parquet read options.

readParquet :: FilePath -> IO DataFrame #

Read a parquet file from path and load it into a dataframe.

readParquetWithOpts :: ParquetReadOptions -> FilePath -> IO DataFrame #

Read a Parquet file using explicit read options.

readParquetFiles :: FilePath -> IO DataFrame #

Read Parquet files from a directory or glob path.

readParquetFilesWithOpts :: ParquetReadOptions -> FilePath -> IO DataFrame #

Read multiple Parquet files (directory or glob) using options.

Lazy query engine

run :: LazyDataFrame -> IO DataFrame #

Optimise and stream-execute the lazy query into a DataFrame.

data LazyDataFrame #

A lazy query: a LogicalPlan whose execution waits for run.

fromDataFrame :: DataFrame -> LazyDataFrame #

Lift an already-loaded eager DataFrame into the lazy plan.

scanCsv :: Schema -> Text -> LazyDataFrame #

Scan a CSV file with the default comma separator and strict reader.

scanCsvWith :: CsvReader -> Schema -> Text -> LazyDataFrame #

Like scanCsv but with an explicit CsvReader.

scanSeparated :: Char -> Schema -> Text -> LazyDataFrame #

Scan a character-separated file with the default strict reader.

scanSeparatedWith :: CsvReader -> Char -> Schema -> Text -> LazyDataFrame #

Like scanSeparated but with an explicit CSV reader.

scanParquet :: Schema -> Text -> LazyDataFrame #

Scan a Parquet file, directory of files, or glob pattern.

Feature synthesis & decision trees

Type conversion

data SafeReadMode #

How parse failures are surfaced: throw, Nothing, or Left raw text.

data ParseOptions #

Options controlling how text columns are parsed into typed values.

Constructors

ParseOptions 

Fields

defaultParseOptions :: ParseOptions #

Sensible out-of-the-box parse options: infer from 100 rows, ISO dates.

effectiveSafeRead :: SafeReadMode -> [(Text, SafeReadMode)] -> Text -> SafeReadMode #

Resolve a column's effective SafeReadMode: override if present.

Operations

filter :: Expr Bool -> DataFrame -> DataFrame #

O(k) Filter the dataframe with a boolean expression.

sample :: RandomGen g => g -> Double -> DataFrame -> DataFrame #

Sample a dataframe; the fraction must be between 0 and 1 inclusive.

range :: (Int, Int) -> DataFrame -> DataFrame #

O(k * n) Take a range of rows of a DataFrame.

take :: Int -> DataFrame -> DataFrame #

O(k * n) Take the first n rows of a DataFrame.

drop :: Int -> DataFrame -> DataFrame #

O(k * n) Drop the first n rows of a DataFrame.

select :: [Text] -> DataFrame -> DataFrame #

O(n) Select a number of columns in a given dataframe.

filterBy #

Arguments

:: Columnable a 
=> (a -> Bool)

Filter condition

-> Expr a

Column to filter by

-> DataFrame

Dataframe to filter

-> DataFrame 

O(n * k) Keep rows whose value of the expression satisfies the predicate.

filterJust :: Text -> DataFrame -> DataFrame #

O(k) Remove all rows with Nothing in a given column.

filterNothing :: Text -> DataFrame -> DataFrame #

O(k) Return all rows with Nothing in a given column.

filterAllJust :: DataFrame -> DataFrame #

O(n * k) Remove all rows with Nothing from the dataframe.

filterAllNothing :: DataFrame -> DataFrame #

O(n * k) Keep any row with a null value.

takeLast :: Int -> DataFrame -> DataFrame #

O(k * n) Take the last n rows of a DataFrame.

dropLast :: Int -> DataFrame -> DataFrame #

O(k * n) Drop the last n rows of a DataFrame.

cube :: (Int, Int) -> DataFrame -> DataFrame #

O(k) Cut the dataframe to a cube of size (length, width).

selectRows :: [Int] -> DataFrame -> DataFrame #

O(k * n) Select rows by index.

randomSplit :: RandomGen g => g -> Double -> DataFrame -> (DataFrame, DataFrame) #

Split a dataset in two: a sample of fraction p and the remainder.

kFolds :: RandomGen g => g -> Int -> DataFrame -> [DataFrame] #

Create n folds of a dataframe.

stratifiedSample :: forall a g. (SplittableGen g, Columnable a) => g -> Double -> Expr a -> DataFrame -> DataFrame #

Sample a dataframe, preserving per-stratum proportions.

stratifiedSplit :: forall a g. (SplittableGen g, Columnable a) => g -> Double -> Expr a -> DataFrame -> (DataFrame, DataFrame) #

Split a dataframe into two, preserving per-stratum proportions.

selectBy :: [SelectionCriteria] -> DataFrame -> DataFrame #

O(n) select columns by column predicate name.

exclude :: [Text] -> DataFrame -> DataFrame #

O(n) Inverse of select.

byName :: Text -> SelectionCriteria #

Criteria for selecting a column by name.

byProperty :: (Column -> Bool) -> SelectionCriteria #

Criteria for selecting columns whose property satisfies a predicate.

byNameProperty :: (Text -> Bool) -> SelectionCriteria #

Criteria for selecting columns whose name satisfies a predicate.

byNameRange :: (Text, Text) -> SelectionCriteria #

Criteria for selecting columns whose names are in a lexicographic range.

byIndexRange :: (Int, Int) -> SelectionCriteria #

Criteria for selecting columns whose indices are in an inclusive range.

apply #

Arguments

:: (Columnable b, Columnable c) 
=> (b -> c)

function to apply

-> Text

Column name

-> DataFrame

DataFrame to apply operation to

-> DataFrame 

O(k) Apply a function to a given column in a dataframe.

derive :: Columnable a => Text -> Expr a -> DataFrame -> DataFrame #

O(k) Derive a new column named alias from an expression.

deriveWithExpr :: Columnable a => Text -> Expr a -> DataFrame -> (Expr a, DataFrame) #

O(k) Like derive but also returns a reference to the new column.

impute :: ImputeOp a => Expr a -> BaseType a -> DataFrame -> DataFrame #

Replace all instances of Nothing in a column with the given value.

applyInt #

Arguments

:: Columnable b 
=> (Int -> b)

function to apply

-> Text

Column name

-> DataFrame

DataFrame to apply operation to

-> DataFrame 

O(k) Convenience function that applies to an int column.

applyDouble #

Arguments

:: Columnable b 
=> (Double -> b)

function to apply

-> Text

Column name

-> DataFrame

DataFrame to apply operation to

-> DataFrame 

O(k) Convenience function that applies to an double column.

applyMany :: (Columnable b, Columnable c) => (b -> c) -> [Text] -> DataFrame -> DataFrame #

O(k * n) Apply a function to given column names in a dataframe.

applyWhere #

Arguments

:: (Columnable a, Columnable b) 
=> (a -> Bool)

Filter condition

-> Text

Criterion Column

-> (b -> b)

function to apply

-> Text

Column name

-> DataFrame

DataFrame to apply operation to

-> DataFrame 

O(k * n) Apply a function to a column where another column matches.

applyAtIndex #

Arguments

:: Columnable a 
=> Int

Index

-> (a -> a)

function to apply

-> Text

Column name

-> DataFrame

DataFrame to apply operation to

-> DataFrame 

O(k) Apply a function to the column at a given index.

safeApply #

Arguments

:: (Columnable b, Columnable c) 
=> (b -> c)

function to apply

-> Text

Column name

-> DataFrame

DataFrame to apply operation to

-> Either DataFrameException DataFrame 

O(k) Safe version of apply. Returns the error instead of throwing.

groupBy :: [Text] -> DataFrame -> GroupedDataFrame #

O(k * n) group the dataframe by the given key columns via a hash table.

aggregate :: [NamedExpr] -> GroupedDataFrame -> DataFrame #

Aggregate a grouped dataframe using the expressions given.

distinct :: DataFrame -> DataFrame #

Filter out all non-unique values in a dataframe.

sortBy :: [SortOrder] -> DataFrame -> DataFrame #

O(k log n) Sort the dataframe by the given sort orders.

data SortOrder where #

Sort order taken as a parameter by the sortBy function.

Constructors

Asc :: forall a. (Columnable a, Ord a) => Expr a -> SortOrder 
Desc :: forall a. (Columnable a, Ord a) => Expr a -> SortOrder 

Instances

Instances details
Show SortOrder 
Instance details

Defined in DataFrame.Operations.Permutation

Eq SortOrder 
Instance details

Defined in DataFrame.Operations.Permutation

topBy :: Int -> Int -> [SortOrder] -> DataFrame -> DataFrame #

The rows a sortBy would place at positions [offset, offset + count).

join :: JoinType -> [Text] -> DataFrame -> DataFrame -> DataFrame #

Join two dataframes using SQL join semantics.

data JoinType #

Equivalent to SQL join types.

Constructors

INNER 
LEFT 
RIGHT 
FULL_OUTER 

Instances

Instances details
Show JoinType 
Instance details

Defined in DataFrame.Operations.Join

joinOn :: JoinType -> [(Text, Text)] -> DataFrame -> DataFrame -> DataFrame #

Join on (leftKey, rightKey) pairs; the result keeps the left names.

innerJoin :: [Text] -> DataFrame -> DataFrame -> DataFrame #

Inner join on two dataframes using the specified key columns.

leftJoin :: [Text] -> DataFrame -> DataFrame -> DataFrame #

Left join on two dataframes, keeping every row from the left dataframe.

rightJoin :: [Text] -> DataFrame -> DataFrame -> DataFrame #

Right join on two dataframes, keeping every row from the right dataframe.

Errors

Record bridge

class HasSchema a where #

Bridge a Haskell record type to a typed-dataframe schema.

Associated Types

type Schema a :: [(Symbol, Type)] #

type family Schema a :: [(Symbol, Type)] #

fromRecords :: HasSchema a => [a] -> DataFrame #

Build an untyped DataFrame from a list of records.

toRecords :: HasSchema a => DataFrame -> Either Text [a] #

Parse a list of records out of an untyped DataFrame.

schemaColumnNames :: forall (cols :: [(Symbol, Type)]). KnownSchema cols => [Text] #

The column names a schema declares, in schema order.

Template Haskell column-binding splices

declareColumnsFromCsvFile :: String -> DecsQ #

Splice an Expr T binding for every column of a CSV file.

declareColumnsFromParquetFile :: String -> DecsQ #

Splice a binding for every column of a parquet file or directory.

declareColumns :: DataFrame -> DecsQ #

Splice a binding for every column of df, named after the column.

declareColumnsWithPrefix :: Text -> DataFrame -> DecsQ #

Like declareColumns but prefixes every binding name with prefix_.

declareColumnsWithPrefix' :: Maybe Text -> DataFrame -> DecsQ #

Like declareColumnsWithPrefix but takes an optional prefix.

declareSchemaValues :: String -> DataFrame -> DecsQ #

Splice a runtime Schema for df along with per-column Expr refs.

Plotting