Skip to content

Instantly share code, notes, and snippets.

@willingc
Created November 5, 2024 19:46
Show Gist options
  • Save willingc/838fbe0187869672f75157dea0be7066 to your computer and use it in GitHub Desktop.
Save willingc/838fbe0187869672f75157dea0be7066 to your computer and use it in GitHub Desktop.
napari hub lite proof of concept
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "8be3818c-1f22-4a4f-bf90-012460d4123a",
"metadata": {},
"source": [
"# Pandas"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e3a97f58-79ce-4fce-b9c5-50d95cf5c0ab",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7ef2fedc-0a69-4cab-ae60-5a07d4d2b185",
"metadata": {},
"outputs": [],
"source": [
"df_cleaned = pd.read_csv('./data/cleaned_napari_plugins.csv')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e68f9d81-24ec-4ea9-86fa-17010c6db529",
"metadata": {},
"outputs": [],
"source": [
"df_cleaned.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9bf6b768-58c5-4005-bf75-ea12c297dfca",
"metadata": {},
"outputs": [],
"source": [
"df_final = pd.read_csv('./data/final_plugins.csv')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8fd2d5de-0a7f-4785-b43c-3f4cb8374a6f",
"metadata": {},
"outputs": [],
"source": [
"df_final.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e32235e7-6048-4013-9e67-c016e0283ccb",
"metadata": {},
"outputs": [],
"source": [
"!pip install pyarrow"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "09a41ec0-8ac1-449b-aed6-835ae2d0c3c7",
"metadata": {},
"outputs": [],
"source": [
"!pip install great_tables"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "322af388-43d3-4a0a-8b8d-db9191429c3c",
"metadata": {},
"outputs": [],
"source": [
"!pip install polars"
]
},
{
"cell_type": "markdown",
"id": "c5bf4f8b-f356-4ebd-80b2-38a261ea77a1",
"metadata": {},
"source": [
"# Polars"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3be5b7a0-b30b-4e35-9476-d1d46d609e9e",
"metadata": {},
"outputs": [],
"source": [
"import polars as pl\n",
"from great_tables import GT, md, html\n",
"from great_tables.data import islands\n",
"\n",
"df_cleaned_mini = (\n",
" pl.from_pandas(df_cleaned).sort(\"display_name\", descending=True)\n",
" .head(10)\n",
")\n",
"\n",
"(\n",
" GT(df_cleaned_mini)\n",
" .tab_header(\n",
" title=\"Napari plugins\",\n",
" subtitle=\"proof of concept\"\n",
" )\n",
" .tab_stub(rowname_col=\"name\")\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9bf5b03b-c486-42f2-9736-8366c61ca729",
"metadata": {},
"outputs": [],
"source": [
"plugins_mini = (\n",
" pl.from_pandas(df_cleaned).sort(\"name\", descending=True)\n",
" .head(10)\n",
")\n",
"\n",
"(\n",
" GT(plugins_mini)\n",
" .tab_header(\n",
" title=\"napari plugins\",\n",
" subtitle=\"proof of concept\"\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "accecbac-16c8-4236-92ef-da6f27a60213",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "1d66389f-384b-4e08-bb4c-047b8c9d8318",
"metadata": {},
"outputs": [],
"source": [
"pl_cleaned_plugins = pl.from_pandas(df_cleaned)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "09e033f2-5b59-41a8-86c1-5269ea15b4b4",
"metadata": {},
"outputs": [],
"source": [
"df_cleaned.columns"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc4014e0-7447-48b9-a9a9-0b40a63a3238",
"metadata": {},
"outputs": [],
"source": [
"import polars as pl\n",
"\n",
"df_pl_final = pl.read_csv(\"./data/final_plugins.csv\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8e360d0a-dd44-43cd-95e5-27f5f378ed21",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"df_pl_final.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "96cca24f-52dc-4fd5-ab52-13457cb5b50a",
"metadata": {},
"outputs": [],
"source": [
"from itables import init_notebook_mode\n",
"\n",
"init_notebook_mode(all_interactive=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7a55b174-b760-4a0b-a0ec-2289b4f17df3",
"metadata": {},
"outputs": [],
"source": [
"df_cleaned"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a84548e5-c154-4961-bbdf-6a8f5d35c7d3",
"metadata": {},
"outputs": [],
"source": [
"from great_tables import GT, md, html\n",
"\n",
"# Create a display table showing ten of the largest islands in the world\n",
"gt_tbl = GT(df_pl_final)\n",
"\n",
"# Show the output table\n",
"gt_tbl"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9465db76-1d7c-4eb0-9a9e-b00aa07caad2",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment