DataFrame utils
PlanarCore.Data.DFUtils — Module
Utilities for DataFrames.jl, prominently timeframe based indexing.
PlanarCore.Data.DFUtils._mutatemax! — Method
Mutates v to df ensuring the dataframe never grows larger than maxlen.
_mutatemax!(df, v, maxlen, n, mut; cols)
PlanarCore.Data.DFUtils.addcols! — Method
Inserts rows in src to dst, zeroing columns not present in dst.
addcols!(dst, src)
PlanarCore.Data.DFUtils.appendmax! — Method
See _mutatemax!
PlanarCore.Data.DFUtils.colnames — Method
Get the column names for dataframe as symbols.
colnames(df::DataFrames.AbstractDataFrame) -> Any
PlanarCore.Data.DFUtils.copysubs! — Method
Replaces subarrays with arrays.
copysubs!(df::DataFrames.AbstractDataFrame) -> Any
copysubs!(df::DataFrames.AbstractDataFrame, copyfunc) -> Any
copysubs!(
df::DataFrames.AbstractDataFrame,
copyfunc,
elsefunc
) -> Any
PlanarCore.Data.DFUtils.dateindex — Method
Same dateindex(::AbstractDataFrame, ::DateTime) but always returns the first index if the index is not found in the vector.
PlanarCore.Data.DFUtils.dateindex — Method
Get the position of date in the :timestamp column of the dataframe based on timeframe arithmentics.
dateindex(
df::DataFrames.AbstractDataFrame,
date::Dates.DateTime,
_::Val{:timeframe}
) -> Any
PlanarCore.Data.DFUtils.dateindex — Method
Get the position of date in the :timestamp column of the dataframe.
dateindex(
df::DataFrames.AbstractDataFrame,
date::Dates.DateTime
) -> Union{Int64, DataStructures.Tokens.IntSemiToken}
PlanarCore.Data.DFUtils.dateindex — Method
Same dateindex(::AbstractVector, ::DateTime) but always returns the first index if the index is not found in the vector.
PlanarCore.Data.DFUtils.dateindex — Method
Same as dateindex
PlanarCore.Data.DFUtils.daterange — Method
Get the date range of a DataFrame.
daterange(
df::DataFrames.AbstractDataFrame
) -> PlanarCore.TimeTicks.DateRange
daterange(
df::DataFrames.AbstractDataFrame,
tf
) -> PlanarCore.TimeTicks.DateRange
daterange(
df::DataFrames.AbstractDataFrame,
tf,
rightofs
) -> PlanarCore.TimeTicks.DateRange
Used to get the date range of a DataFrame df. It takes in the DataFrame df, an optional timeframe tf (default is the current timeframe of the DataFrame), and an optional rightofs parameter. The rightofs parameter specifies the number of steps to shift the date range to the right. For example, if rightofs is set to 1, the date range will be shifted one step to the right. This can be useful for calculating future date ranges based on the current date range. Returns the date range of the DataFrame df based on the specified timeframe tf and rightofs parameter.
PlanarCore.Data.DFUtils.firstdate — Method
Get the first timestamp in the dataframe (:timestamp column).
PlanarCore.Data.DFUtils.getdate — Method
Get the date-based subset of a DataFrame.
getdate(
df::DataFrames.AbstractDataFrame,
dr::Union{PlanarCore.TimeTicks.DateRange, StepRange{Dates.DateTime, <:Dates.Period}},
cols
) -> Any
getdate(
df::DataFrames.AbstractDataFrame,
dr::Union{PlanarCore.TimeTicks.DateRange, StepRange{Dates.DateTime, <:Dates.Period}},
cols,
tf
) -> Any
Indexing by date ranges allows to query ohlcv using the timestamp column as index, assuming that the data has no missing values and is already sorted.
Examples: df[dtr"1999-.."] # Starting from 1999 up to the end df[dtr"..1999-"] # From the beginning up to 1999 df[dtr"1999-..2000-"] # The Year 1999
PlanarCore.Data.DFUtils.getdate — Method
Get the specified columns based on given date (used as index).
getdate(
df::DataFrames.AbstractDataFrame,
idx::Dates.DateTime,
cols
) -> Any
getdate(
df::DataFrames.AbstractDataFrame,
idx::Dates.DateTime,
cols,
tf::TimeFrames.TimeFrame
) -> Any
While indexing ohlcv data we have to consider the time of arrival of a candle. In general candles collect the price up to its timestamp. E.g. the candle at time 2000-01-01 would have tracked time from 1999-12-31T00:00:00 to 2000-01-01T00:00:00. Therefore what we return is always the left adjacent timestamp of the queried one.
PlanarCore.Data.DFUtils.lastdate — Method
Get the last timestamp in the dataframe (:timestamp column).
PlanarCore.Data.DFUtils.prependmax! — Method
See _mutatemax!
PlanarCore.Data.DFUtils.pushmax! — Method
See _mutatemax!
PlanarCore.Data.DFUtils.setcols! — Function
Set the values of specific columns in one DataFrame from another DataFrame.
setcols!(dst, src, cols)
setcols!(dst, src, cols, idx)
Used to set the values of specific columns in one DataFrame dst from another DataFrame src. It takes in the destination DataFrame dst, the source DataFrame src, the columns to set cols, and optional indices idx to specify the rows to set. The cols parameter specifies the columns in the destination DataFrame dst that will be set with the corresponding values from the source DataFrame src. The idx parameter specifies the indices of the rows in the destination DataFrame dst that will be set. By default, it sets all rows. It mutates the destination DataFrame dst by setting the values of the specified columns cols with the corresponding values from the source DataFrame src.
PlanarCore.Data.DFUtils.timeframe!! — Method
Forcefully infers the dataframe timeframe. See timeframe!(::DataFrame)
PlanarCore.Data.DFUtils.viewfrom — Method
Create a view of an OHLCV DataFrame starting from a specific index.
viewfrom(ohlcv, from::Integer; offset, cols) -> Any
Used to create a view of an OHLCV DataFrame ohlcv starting from a specific index from. It takes in the OHLCV DataFrame ohlcv, the starting index from as an integer, and optional parameters offset and cols. The offset parameter specifies the number of rows to offset the view from the starting index. The default value is 0, indicating no offset. The cols parameter specifies the columns to include in the view. By default, all columns are included. Returns a view of the original OHLCV DataFrame ohlcv starting from the specified index from, with an optional offset and specified columns.
PlanarCore.Data.DFUtils.zerorow — Method
The zeroed row of a dataframe (zero(el) from every column).
PlanarCore.Misc.after — Function
Get the subset of a DataFrame containing rows after a specific date.
after(
df::DataFrames.DataFrame,
dt::Dates.DateTime
) -> DataFrames.SubDataFrame{DataFrames.DataFrame, DataFrames.Index, UnitRange{Int64}}
after(
df::DataFrames.DataFrame,
dt::Dates.DateTime,
cols
) -> Any
This function is used to get the subset of a DataFrame df that contains rows after a specific date dt. It takes in the DataFrame df, the specific date dt as a DateTime object, and optional columns cols to include in the subset. If cols is not specified, the function includes all columns in the subset. If cols is specified, only the columns listed in cols will be included in the subset. This function returns a DataFrameView that contains only the rows of df that occur after the specified date dt and the specified columns cols.
PlanarCore.Misc.before — Function
Complement of after
PlanarCore.TimeTicks.timeframe! — Method
Infer the dataframe's timeframe from the timestamp column of the dataframe and sets it.
PlanarCore.TimeTicks.timeframe! — Method
Sets the dataframe's timeframe metadata to the given TimeFrame.
Shouldn't be called directly, see timeframe!(::DataFrame)
PlanarCore.TimeTicks.timeframe — Method
Returns the timeframe of a dataframe according to its metadata.
timeframe(
df::DataFrames.AbstractDataFrame
) -> TimeFrames.TimeFrame
If the value is not found in the metadata, infer it by timestamp column of the dataframe. If the timeframe can't be inferred, a TimeFrame(0) is returned. NOTE: slow func, for speed use timeframe!(::DataFrame)
See Also
- Data Management - Guide: Data handling and management
- Exchanges - Data handling and management