bw2data.backends.proxies
#
Module Contents#
Classes#
A MutableMapping is a generic container for associating |
|
A MutableMapping is a generic container for associating |
|
Iterator for exchanges with some additional methods. |
- class bw2data.backends.proxies.Activity(document=None, **kwargs)[source]#
Bases:
bw2data.proxies.ActivityProxyBase
A MutableMapping is a generic container for associating key/value pairs.
This class provides concrete generic implementations of all methods except for __getitem__, __setitem__, __delitem__, __iter__, and __len__.
Create an Activity proxy object.
If this is a new activity, can pass kwargs.
If the activity exists in the database, document should be an ActivityDataset.
- copy(code=None, **kwargs)[source]#
Copy the activity. Returns a new Activity.
code is the new activity code; if not given, a UUID is used.
kwargs are additional new fields and field values, e.g. name=โfooโ
- class bw2data.backends.proxies.Exchange(document=None, **kwargs)[source]#
Bases:
bw2data.proxies.ExchangeProxyBase
A MutableMapping is a generic container for associating key/value pairs.
This class provides concrete generic implementations of all methods except for __getitem__, __setitem__, __delitem__, __iter__, and __len__.
Create an Exchange proxy object.
If this is a new exchange, can pass kwargs.
If the exchange exists in the database, document should be an ExchangeDataset.
- class bw2data.backends.proxies.Exchanges(key, kinds=None, reverse=False)[source]#
Bases:
collections.abc.Iterable
Iterator for exchanges with some additional methods.
This is not a generator;
next()
is not supported. Everything time you start to iterate over the object you get a new list starting from the beginning. However, to get a single item you can donext(iter(foo))
.Ordering is by database row id.
Supports the following:
exchanges = activity.exchanges() # Iterate for exc in exchanges: pass # Length len(exchanges) # Delete all exchanges.delete()
- to_dataframe(categorical: bool = True, formatters: Optional[List[Callable]] = None) pandas.DataFrame [source]#
Return a pandas DataFrame with all node exchanges. Standard DataFrame columns are:
target_id: int, target_database: str, target_code: str, target_name: Optional[str], target_reference_product: Optional[str], target_location: Optional[str], target_unit: Optional[str], target_type: Optional[str] source_id: int, source_database: str, source_code: str, source_name: Optional[str], source_product: Optional[str], # Note different label source_location: Optional[str], source_unit: Optional[str], source_categories: Optional[str] # Tuple concatenated with โ::โ as in bw2io edge_amount: float, edge_type: str,
Target is the node consuming the edge, source is the node or flow being consumed. The terms target and source were chosen because they also work well for biosphere edges.
Args:
categorical
will turn each string column in a pandas Categorical Series. This takes 1-2 extra seconds, but saves around 50% of the memory consumption.formatters
is a list of callables that modify each row. These functions must take the following keyword arguments, and use the Wurst internal data format:node
: The target node, as a dictedge
: The edge, including attributes of the source noderow
: The current row dict being modified.
The functions in
formatters
donโt need to return anything, they modifyrow
in place.Returns a pandas
DataFrame
.