analysis¶
Table-level questions: partner rankings and category comparisons. partners and compare_categories are re-exported as nv.partners and nv.compare_categories.
Table-level questions about flows: who a node exchanges with, and how categories compare.
Role
module-attribute
¶
Which flows of the focal node to rank: outgoing ("out", for trade its
export destinations), incoming ("in", its import sources), or both side by
side.
CategoryMetric
module-attribute
¶
CategoryMetric: TypeAlias = Literal[
"total_weight",
"n_flows",
"n_sources",
"n_targets",
"n_nodes",
]
Metrics for compare_categories: total weight, number of flow
rows, number of distinct sources, of distinct targets, and of distinct nodes
(sources and targets combined).
suggest
¶
Return up to n choices that resemble name.
Substring matches (case-insensitive) come first, then fuzzy matches from
difflib.get_close_matches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The string that failed to match. |
required |
choices
|
Iterable[str]
|
Candidate strings. |
required |
n
|
int
|
Maximum number of suggestions. |
5
|
Returns:
| Type | Description |
|---|---|
list of str
|
Suggestions, best first, without duplicates. |
partners
¶
partners(
flows: FlowFrame,
node: str,
role: Role = "out",
*,
top_n: int | None = 10,
time: int | Iterable[int] | None = None,
category: Hashable | Iterable[Hashable] | None = None,
) -> DataFrame
Rank the partners of one node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flows
|
FlowFrame
|
A flow frame. |
required |
node
|
str
|
The focal node, matched exactly against |
required |
role
|
Role
|
|
'out'
|
top_n
|
int | None
|
Number of partners to return. |
10
|
time
|
int | Iterable[int] | None
|
Optional filters, each a value or an iterable of values, applied
before ranking. Without them, flows over all times and categories in
|
None
|
category
|
int | Iterable[int] | None
|
Optional filters, each a value or an iterable of values, applied
before ranking. Without them, flows over all times and categories in
|
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Indexed by |
Raises:
| Type | Description |
|---|---|
UnknownNodeError
|
If |
MixedUnitError
|
If the flows being summed have more than one unit. |
ValueError
|
If |
Examples:
compare_categories
¶
compare_categories(
flows: FlowFrame,
metric: CategoryMetric = "total_weight",
*,
by_time: bool = False,
) -> DataFrame | Series
Compare categories (for trade, commodities) on one metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flows
|
FlowFrame
|
A flow frame containing one or more categories. |
required |
metric
|
CategoryMetric
|
|
'total_weight'
|
by_time
|
bool
|
Return one column per |
False
|
Returns:
| Type | Description |
|---|---|
Series or DataFrame
|
Indexed by category, sorted in descending order of the metric (of the
latest time value when |
Raises:
| Type | Description |
|---|---|
UnknownMetricError
|
If |
Examples: