# Convert some data into Panda DataFrames
## British Petroleum (BP)
It parse sheet like `Primary Energy Consumption` (not like `Primary Energy - Cons by fuel`).
Open: http://www.bp.com/statisticalreview
or https://www.bp.com/en/global/corporate/energy-economics/statistical-review-of-world-energy.html
Download `Statistical Review of World Energy – all data`.
Use:
```python
from shifter_pandas.bp import UNITS_ENERGY, BPDatasource
shifter_ds = BPDatasource("bp-stats-review-2021-all-data.xlsx")
df = shifter_ds.datasource(units_filter=UNITS_ENERGY, regions_filter=["Switzerland"])
df
```
## Swiss Office Federal of Statistics (OFS)
From https://www.bfs.admin.ch/bfs/fr/home/services/recherche/stat-tab-donnees-interactives.html
create a stat table.
Click on `À propos du tableau`
Click on `Rendez ce tableau disponible dans votre application`
Use:
```python
from shifter_pandas.ofs import OFSDatasource
shifter_ds = OFSDatasource("<URL>")
df = shifter_ds.datasource(<Requête Json>)
df
```
And replace `<URL>` and `<Requête Json>` with the content of the fields of the OFS web page.
### Interesting sources
- [Parc de motocycles par caractéristiques techniques et émissions](https://www.pxweb.bfs.admin.ch/pxweb/fr/px-x-1103020100_165/-/px-x-1103020100_165.px/)
- [Bilan démographique selon l'âge et le canton](https://www.pxweb.bfs.admin.ch/pxweb/fr/px-x-0102020000_104/-/px-x-0102020000_104.px/)
## Our World in Data
Select a publication.
Click `Download`.
Click `Full data (CSV)`.
Use:
```python
import pandas as pd
from shifter_pandas.wikidata_ import WikidataDatasource
df_owid = pd.read_csv("<file name>")
wdds = WikidataDatasource()
df_wd = wdds.datasource_code(wikidata_id=True, wikidata_name=True, wikidata_type=True)
df = pd.merge(df_owid, df_wd, how="inner", left_on='iso_code', right_on='Code')
df
```
### Interesting sources
- [GDP, 1820 to 2018](https://ourworldindata.org/grapher/gdp-world-regions-stacked-area)
- [Population, 1800 to 2021](https://ourworldindata.org/grapher/population-since-1800)
## World Bank
Open https://data.worldbank.org/
Find a chart
In `Download` click `CSV`
Use:
```python
from shifter_pandas.worldbank import wbDatasource
df = wbDatasource("<file name>")
df
```
### Interesting sources
- [GDP (current US$)](https://data.worldbank.org/indicator/NY.GDP.MKTP.CD)
- [GDP (constant 2015 US$)](https://data.worldbank.org/indicator/NY.GDP.MKTP.KD)
## Wikidata
By providing the `wikidata_*` parameters, you can ass some data from WikiData.
Careful, the WikiData is relatively slow then the first time you run it il will be slow.
We use a cache to make it fast the next times.
You can also get the country list with population and ISO 2 code with:
```python
from shifter_pandas.wikidata_ import (
ELEMENT_COUNTRY,
PROPERTY_ISO_3166_1_ALPHA_2,
PROPERTY_POPULATION,
WikidataDatasource,
)
shifter_ds = WikidataDatasource()
df = shifter_ds.datasource(
instance_of=ELEMENT_COUNTRY,
with_id=True,
with_name=True,
properties=[PROPERTY_ISO_3166_1_ALPHA_2, PROPERTY_POPULATION],
limit=1000,
)
df
```
## Contributing
Install the pre-commit hooks:
```bash
pip install pre-commit
pre-commit install --allow-missing-config
```
Raw data
{
"_id": null,
"home_page": "https://hub.docker.com/r/sbrunner/shifter-pandas/",
"name": "shifter-pandas",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<3.13",
"maintainer_email": "",
"keywords": "shifter,pandas",
"author": "St\u00e9phane Brunner",
"author_email": "stephane.brunner@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/7b/bd/e195d094411aa5c38f404e0b6f924ac6bd0b024e90f2d27d95367878a957/shifter_pandas-0.4.0.tar.gz",
"platform": null,
"description": "# Convert some data into Panda DataFrames\n\n## British Petroleum (BP)\n\nIt parse sheet like `Primary Energy Consumption` (not like `Primary Energy - Cons by fuel`).\n\nOpen: http://www.bp.com/statisticalreview\nor https://www.bp.com/en/global/corporate/energy-economics/statistical-review-of-world-energy.html\n\nDownload `Statistical Review of World Energy \u2013 all data`.\n\nUse:\n\n```python\nfrom shifter_pandas.bp import UNITS_ENERGY, BPDatasource\n\nshifter_ds = BPDatasource(\"bp-stats-review-2021-all-data.xlsx\")\n\ndf = shifter_ds.datasource(units_filter=UNITS_ENERGY, regions_filter=[\"Switzerland\"])\ndf\n```\n\n## Swiss Office Federal of Statistics (OFS)\n\nFrom https://www.bfs.admin.ch/bfs/fr/home/services/recherche/stat-tab-donnees-interactives.html\ncreate a stat table.\n\nClick on `\u00c0 propos du tableau`\n\nClick on `Rendez ce tableau disponible dans votre application`\n\nUse:\n\n```python\nfrom shifter_pandas.ofs import OFSDatasource\n\nshifter_ds = OFSDatasource(\"<URL>\")\n\ndf = shifter_ds.datasource(<Requ\u00eate Json>)\ndf\n```\n\nAnd replace `<URL>` and `<Requ\u00eate Json>` with the content of the fields of the OFS web page.\n\n### Interesting sources\n\n- [Parc de motocycles par caract\u00e9ristiques techniques et \u00e9missions](https://www.pxweb.bfs.admin.ch/pxweb/fr/px-x-1103020100_165/-/px-x-1103020100_165.px/)\n- [Bilan d\u00e9mographique selon l'\u00e2ge et le canton](https://www.pxweb.bfs.admin.ch/pxweb/fr/px-x-0102020000_104/-/px-x-0102020000_104.px/)\n\n## Our World in Data\n\nSelect a publication.\n\nClick `Download`.\n\nClick `Full data (CSV)`.\n\nUse:\n\n```python\nimport pandas as pd\nfrom shifter_pandas.wikidata_ import WikidataDatasource\n\ndf_owid = pd.read_csv(\"<file name>\")\nwdds = WikidataDatasource()\ndf_wd = wdds.datasource_code(wikidata_id=True, wikidata_name=True, wikidata_type=True)\ndf = pd.merge(df_owid, df_wd, how=\"inner\", left_on='iso_code', right_on='Code')\ndf\n```\n\n### Interesting sources\n\n- [GDP, 1820 to 2018](https://ourworldindata.org/grapher/gdp-world-regions-stacked-area)\n- [Population, 1800 to 2021](https://ourworldindata.org/grapher/population-since-1800)\n\n## World Bank\n\nOpen https://data.worldbank.org/\n\nFind a chart\n\nIn `Download` click `CSV`\n\nUse:\n\n```python\nfrom shifter_pandas.worldbank import wbDatasource\n\ndf = wbDatasource(\"<file name>\")\ndf\n```\n\n### Interesting sources\n\n- [GDP (current US$)](https://data.worldbank.org/indicator/NY.GDP.MKTP.CD)\n- [GDP (constant 2015 US$)](https://data.worldbank.org/indicator/NY.GDP.MKTP.KD)\n\n## Wikidata\n\nBy providing the `wikidata_*` parameters, you can ass some data from WikiData.\n\nCareful, the WikiData is relatively slow then the first time you run it il will be slow.\nWe use a cache to make it fast the next times.\n\nYou can also get the country list with population and ISO 2 code with:\n\n```python\nfrom shifter_pandas.wikidata_ import (\n ELEMENT_COUNTRY,\n PROPERTY_ISO_3166_1_ALPHA_2,\n PROPERTY_POPULATION,\n WikidataDatasource,\n)\n\nshifter_ds = WikidataDatasource()\ndf = shifter_ds.datasource(\n instance_of=ELEMENT_COUNTRY,\n with_id=True,\n with_name=True,\n properties=[PROPERTY_ISO_3166_1_ALPHA_2, PROPERTY_POPULATION],\n limit=1000,\n)\ndf\n```\n\n## Contributing\n\nInstall the pre-commit hooks:\n\n```bash\npip install pre-commit\npre-commit install --allow-missing-config\n```\n\n",
"bugtrack_url": null,
"license": "BSD-2-Clause",
"summary": "Convert some data into Panda DataFrames",
"version": "0.4.0",
"project_urls": {
"Homepage": "https://hub.docker.com/r/sbrunner/shifter-pandas/",
"Repository": "https://github.com/sbrunner/shifter-pandas"
},
"split_keywords": [
"shifter",
"pandas"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "82b747fa28cd33dc4657168709691513d501bece35d39d2d35294253cea80832",
"md5": "90fb51f9102ebacd56a5a9199a70020a",
"sha256": "5e6367c09b3ea0715526ea386198bfdefc9080817df4c8c75ccedf9570be5f08"
},
"downloads": -1,
"filename": "shifter_pandas-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "90fb51f9102ebacd56a5a9199a70020a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<3.13",
"size": 14992,
"upload_time": "2023-09-21T12:29:47",
"upload_time_iso_8601": "2023-09-21T12:29:47.151453Z",
"url": "https://files.pythonhosted.org/packages/82/b7/47fa28cd33dc4657168709691513d501bece35d39d2d35294253cea80832/shifter_pandas-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7bbde195d094411aa5c38f404e0b6f924ac6bd0b024e90f2d27d95367878a957",
"md5": "7be1a088dddf1134b8283f6acea7e772",
"sha256": "33610b0d2fdfe27b169b44c49beac9f13343cef6c2ead6d28a82b4a24b0a4e6e"
},
"downloads": -1,
"filename": "shifter_pandas-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "7be1a088dddf1134b8283f6acea7e772",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<3.13",
"size": 14439,
"upload_time": "2023-09-21T12:29:48",
"upload_time_iso_8601": "2023-09-21T12:29:48.413573Z",
"url": "https://files.pythonhosted.org/packages/7b/bd/e195d094411aa5c38f404e0b6f924ac6bd0b024e90f2d27d95367878a957/shifter_pandas-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-21 12:29:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sbrunner",
"github_project": "shifter-pandas",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "shifter-pandas"
}