DVector#

class caf.base.DVector(segmentation, import_data, zoning_system=None, time_format=None, val_col='val', low_memory=False, cut_read=False, _bypass_validation=False)[source]#

Bases: object

Class to store and manipulate data with segmentation and optionally zoning.

The segmentation is stored as an attribute as well as forming the index of the data. Zoning, if present, is stored as an attribute as well as forming the columns of the data. Data is in the form of a dataframe and reads/writes to h5 along with all metadata.

Attributes

Dict

data

Get _data.

segmentation

Get _segmentation.

time_format

Get _time_format.

total

Return the total of a DVector.

val_col

Name of column containing DVector values, not relevant if DVector has a zoning system.

zoning_system

Get _zoning_system.

Methods

__init__(segmentation, import_data[, ...])

Init method.

add_segments(new_segs[, new_naming_order, ...])

Add a segment to a DVector.

add_value_to_subset(segment, value, data)

Add a value to a subset segment in a DVector.

aggregate(segs[, _bypass_validation])

Aggregate DVector to new segmentation.

aggregate_comp_zones(zone_system)

Aggregate a composite zoned DVector to one of its constituent zoning systems.

balance_by_segments(other[, balancing_zones])

Balance one DVector to another.

calc_rmse(targets)

Calculate the rmse relative to a set of targets.

combine_from_dic(in_dic, new_seg, ...)

Combine DVectors saved in a dictionary.

composite_zoning(new_zoning[, trans_vector])

Composite zoning for DVector from a translation vector.

concat(other)

Analogous to pandas dataframe concat method.

concat_from_dir(folder[, zoning, ...])

Load all DVectors in a directory and concatenate them into a single DVector.

concat_list(dvecs, new_segmentation)

Concatenate a list of DVectors.

concat_to_comp_zoning(dvecs, zone_system)

Concatenate Dvectors to a resulting DVector with composite zoning.

copy([_bypass_validation])

Class copy method.

drop_by_segment_values(segment_name, ...)

Remove rows of DVector based on segment values.

expand_to_other(other[, match_props])

Expand self segmentation to other.

fill(find_value, infill_value)

Replace find_value with infill_value.

fillna(infill_value)

Wrap fillna dataframe method.

filter_segment_value(segment_name, ...[, ...])

Filter a DVector on a given segment.

get_slice(slice_[, allow_closest])

Get a slice (row) of the DVector.

ipf(targets[, tol, max_iters, zone_trans_cache])

Implement iterative proportional fitting for DVectors.

load(in_path[, cut_read])

Load the DVector.

old_to_new_dvec(import_data)

Convert the old format of DVector into the new.

overlap(other)

Call segmentation overlap method to check two DVectors contain overlapping segments.

remove_zoning([fn])

Aggregate all the zone values in DVector into a single value using fn.

rename_segment(mapping)

Rename segments in both the segmentation definition and the associated data.

save(out_path)

Save the DVector.

select_zone(zone_id)

Return a DVector for a single zone in a DVector.

split_by_agg_zoning(agg_zoning[, trans])

Split a DVector into a different new DVector for each aggregate zone.

split_by_other(other[, agg_zone])

Split a DVector adding new segments.

sum()

Sum DVector.

sum_is_close(other, rel_tol, abs_tol)

Check if self sums close to other.

sum_zoning()

Sum over zones.

to_ie()

Convert zoning to internal/external.

trans_and_comp(new_zoning, trans_vector, ...)

Use a trans vector to translate a DVector to a new, composite, zone system.

trans_seg_from_lookup(lookup[, drop_old])

Translate segment(s) in self to new segment(s) from a lookup in SegConverter.

translate_segment(from_seg, to_seg[, ...])

Translate a segment in the DVector.

translate_zoning(new_zoning[, cache_path, ...])

Translate this DVector into another zoning system and returns a new DVector.

validate_ipf_targets(targets[, rel_tol, ...])

Check targets for ipf will work, raises errors if not.

write_sector_reports(segment_totals_path, ...)

Write segment, CA sector, and IE sector reports to disk.

Attributes Documentation

Parameters:
Dict#

alias of Dict

data#

Get _data.

data is a pandas DataFrame or pandas Series. It will have a multiindex comprising the segmentation, and columns comprising the zones, if there are zones.

segmentation#

Get _segmentation.

time_format#

Get _time_format.

total#

Return the total of a DVector.

val_col#

Name of column containing DVector values, not relevant if DVector has a zoning system.

zoning_system#

Get _zoning_system.