![NetCBS: creating network measures using CBS networks (POPNET) in the RA](/images/tutorial-10/planet-volumes-n90vqb47E7M-unsplash_hu5459c0360c2b0cb7a147d2df0eb350ca_1014345_1110x0_resize_q100_box.jpg)
NetCBS: creating network measures using CBS networks (POPNET) in the RA
+ +netCBS
+A Python library to efficiently create network measures using CBS networks (POPNET) in the RA. For example you may be interested in calculating the average income of the parents of the classmates of a student. This package allows you to do this in a fast and efficient way.
+Installation
+pip install netcbs
+
Usage
+See notebook for accessible information and examples.
+Create network measures (e.g. the average income and age of the parents (link type 301) of the classmates of children in the sample)
+query = "[Income, Age] -> Family[301] -> Schoolmates[all] -> Sample"
+df = netcbs.transform(query,
+ df_sample = df_sample, # dataset with the sample to study
+ df_agg = df_agg, # dataset with the income variable
+ year=2021, # year to study
+ cbsdata_path='G:/Bevolking', # path to the CBS data
+ agg_funcs=[pl.mean, pl.sum, pl.count], # calculate the average
+ return_pandas=False, # returns a pandas dataframe instead of a polars dataframe
+ lazy=True # use polars lazy evaluation (faster/less memory usage)
+ )
+
How does the library work?
+Query system
+The library uses a query system to specify the relationships between the main sample dataframe and the context data. The query consists of a series of context types separated by arrows (->), with optional relationship types in square brackets. For example, the query "[Income] -> Family[301] -> Schoolmates[all] -> Sample"
specifies that the income of the parents of the student’s classmates should be calculated based on the provided sample dataframe.
Data used:
+The library checks the latest verion of each network file for the year specified in the transform
function.
The library removes duplicate entries from the df_sample and df_agg dataframes, and converts them to polars for efficient.
+Transformation fo the query
+The validate_query
function (called automatically by the transform
function) ensures that the query string is correctly formatted and that all necessary columns are present in the input dataframes. It splits the query into individual contexts and verifies each part, raising errors for any issues found.
The different network files (contexts) are merged (inner join) consecutively based on the relationship columns specified in the query. The resulting dataframe is then aggregated based on the aggregation function (e.g., pl.mean, pl.sum) specified in the transform
function.
We recommend to use the polars lazy evaluation (lazy=True) to reduce memory usage and speed up the calculations. For debugging this can be disabled by setting lazy=False.
+Contributing
+Contributions are what make the open source community an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
+Please refer to the CONTRIBUTING file for more information on issues and pull requests.
+License and citation
+The package netCBS
is published under an MIT license. When using netCBS
for academic work, please cite:
Garcia-Bernardo, Javier (2024). netCBS: A Python library to efficiently create network measures using CBS networks (POPNET) in the RA (0.1). Zenodo. 10.5281/zenodo.13908120
+
Contact
+This project is developed and maintained by the ODISSEI Social Data +Science (SoDa) team.
+Tutorials
![Detecting communities in signed networks with Python](/images/tutorial-9/algorithm_hu5459c0360c2b0cb7a147d2df0eb350ca_1164949_1110x0_resize_q100_box.jpg)
![NetCBS: creating network measures using CBS networks (POPNET) in the RA](/images/tutorial-10/planet-volumes-n90vqb47E7M-unsplash_hu5459c0360c2b0cb7a147d2df0eb350ca_1014345_1110x0_resize_q100_box.jpg)
Tutorials
Detecting communities in signed networks with Python
-Signed networks are a way to represent relationships between entities. These types of networks are called ‘signed’ because the connections between entities are signed: they can be positive (or cooperative) or negative (or conflicting).
- read more +NetCBS: creating network measures using CBS networks (POPNET) in the RA
+netCBS A Python library to efficiently create network measures using CBS networks (POPNET) in the RA.
+ read more
+
+
+
+
+
+
+
+
+
+
+
+ September 29, 2023
+
+
+ Wrangling interval data using lubridate
+ One common issue we encounter in helping researchers work with the housing register data of Statistics Netherlands is its transactional nature: each row in the housing register table contains data on when someone registered and deregistered at an address (more info in Dutch here).
+ read more
+
+
Wrangling interval data using lubridate
+One common issue we encounter in helping researchers work with the housing register data of Statistics Netherlands is its transactional nature: each row in the housing register table contains data on when someone registered and deregistered at an address (more info in Dutch here).
+ read more +