{"id":21685868,"url":"https://github.com/sodascience/netcbs","last_synced_at":"2025-06-11T00:06:07.313Z","repository":{"id":244193533,"uuid":"800423367","full_name":"sodascience/netCBS","owner":"sodascience","description":"Package to efficiently create network measures using CBS networks (POPNET) in the RA","archived":false,"fork":false,"pushed_at":"2024-10-09T11:31:36.000Z","size":153,"stargazers_count":1,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-22T10:08:56.164Z","etag":null,"topics":["cbs","networks","popnet"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sodascience.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-05-14T09:59:52.000Z","updated_at":"2024-10-09T11:31:39.000Z","dependencies_parsed_at":"2025-04-12T08:13:17.093Z","dependency_job_id":"bc81a444-0ba2-4ada-9dc5-c91c0a70e578","html_url":"https://github.com/sodascience/netCBS","commit_stats":null,"previous_names":["sodascience/netcbs"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sodascience%2FnetCBS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sodascience%2FnetCBS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sodascience%2FnetCBS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sodascience%2FnetCBS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sodascience","download_url":"https://codeload.github.com/sodascience/netCBS/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sodascience%2FnetCBS/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259172962,"owners_count":22816558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cbs","networks","popnet"],"created_at":"2024-11-25T16:23:27.225Z","updated_at":"2025-06-11T00:06:07.286Z","avatar_url":"https://github.com/sodascience.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# netCBS\nA 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.\n\n## Installation\n\n```bash\npip install netcbs\n```\n\n## Usage\n\nSee [notebook](tutorial_netCBS.ipynb) for accessible information and examples.\n\n\n### Create network measures (e.g. the average income and age of the parents (link type 301) of the classmates of children in the sample)\n```python\nquery =  \"[Income, Age] -\u003e Family[301] -\u003e Schoolmates[all] -\u003e Sample\"\ndf = netcbs.transform(query, \n                     df_sample = df_sample,  # dataset with the sample to study\n                     df_agg = df_agg, # dataset with the income variable\n                     year=2021, # year to study\n                     cbsdata_path='G:/Bevolking', # path to the CBS data\n                     agg_funcs=[pl.mean, pl.sum, pl.count], # calculate the average\n                     return_pandas=False, # returns a pandas dataframe instead of a polars dataframe\n                     lazy=True # use polars lazy evaluation (faster/less memory usage)\n                     )\n\n```\n\n## How does the library work?\n### Query system\nThe 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 (-\u003e), with optional relationship types in square brackets. For example, the query `\"[Income] -\u003e Family[301] -\u003e Schoolmates[all] -\u003e Sample\"` specifies that the income of the parents of the student's classmates should be calculated based on the provided sample dataframe.\n\n### Data used:\nThe library checks the latest verion of each network file for the year specified in the `transform` function. \n\nThe library removes duplicate entries from the df_sample and df_agg dataframes, and converts them to polars for efficient.\n\n### Transformation fo the query\nThe `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.\n\nThe 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.\n\nWe 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.\n\n\n## Contributing\nContributions are what make the open source community an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\nPlease refer to the [CONTRIBUTING](https://github.com/sodascience/netcbs/blob/main/CONTRIBUTING.md) file for more information on issues and pull requests.\n\n## License and citation\n\nThe package `netCBS` is published under an MIT license. When using `netCBS` for academic work, please cite:\n```\nGarcia-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\n```\n\n## Contact\n\nThis project is developed and maintained by the [ODISSEI Social Data\nScience (SoDa)](https://odissei-data.nl/nl/soda/) team.\n\n\u003cimg src=\"soda_logo.png\" alt=\"SoDa logo\" width=\"250px\"/\u003e\n\nDo you have questions, suggestions, or remarks? File an issue in the issue\ntracker or feel free to contact the team via\nhttps://odissei-data.nl/en/using-soda/.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsodascience%2Fnetcbs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsodascience%2Fnetcbs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsodascience%2Fnetcbs/lists"}