Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lisphilar/1d0d45946a8b583f999cd06d46bad561 to your computer and use it in GitHub Desktop.
Save lisphilar/1d0d45946a8b583f999cd06d46bad561 to your computer and use it in GitHub Desktop.
polars_0-20-22_cell_alignment_display.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"toc_visible": true,
"authorship_tag": "ABX9TyMRgs+cM6ip+4GkPOasa6zk",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/lisphilar/1d0d45946a8b583f999cd06d46bad561/polars_0-20-22_cell_alignment_display.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"!pip install polars -U"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "5aJNaFi5_ZIO",
"outputId": "7e32446a-793d-4f9f-87f7-4cb69593becd"
},
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: polars in /usr/local/lib/python3.10/dist-packages (0.20.2)\n",
"Collecting polars\n",
" Downloading polars-0.20.22-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (27.4 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m27.4/27.4 MB\u001b[0m \u001b[31m14.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hInstalling collected packages: polars\n",
" Attempting uninstall: polars\n",
" Found existing installation: polars 0.20.2\n",
" Uninstalling polars-0.20.2:\n",
" Successfully uninstalled polars-0.20.2\n",
"Successfully installed polars-0.20.22\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"from datetime import date\n",
"import polars as pl"
],
"metadata": {
"id": "w78pfSbW_ZIO"
},
"execution_count": 2,
"outputs": []
},
{
"cell_type": "code",
"source": [
"df = pl.DataFrame(\n",
" {\n",
" \"long_words\": [\"Hollo Word!\", \"Thank you!\", \"Blazingly fast DataFrame!!\"],\n",
" \"column_abc\": [1.0, 2.5, 5.0],\n",
" \"column_xyz\": [True, False, True],\n",
" \"abc\": [11, 2, 333],\n",
" \"mno\": [date(2023, 10, 29), None, date(2001, 7, 5)],\n",
" \"xyz\": [True, False, None],\n",
" }\n",
")"
],
"metadata": {
"id": "euRA_zzD_ZIO"
},
"execution_count": 3,
"outputs": []
},
{
"cell_type": "code",
"source": [
"pl.Config.set_tbl_cell_alignment(\"LEFT\")\n",
"pl.Config.set_tbl_cell_numeric_alignment(\"LEFT\")\n",
"_ = pl.Config.set_fmt_str_lengths(50)"
],
"metadata": {
"id": "r0edWr4Q_ZIO"
},
"execution_count": 4,
"outputs": []
},
{
"cell_type": "code",
"source": [
"print(df)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "b5c7a778-0fea-4bdc-b0e9-ec2cf49bb6b2",
"id": "VKZULLNY_ZIO"
},
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"shape: (3, 6)\n",
"┌────────────────────────────┬────────────┬────────────┬─────┬────────────┬───────┐\n",
"│ long_words ┆ column_abc ┆ column_xyz ┆ abc ┆ mno ┆ xyz │\n",
"│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
"│ str ┆ f64 ┆ bool ┆ i64 ┆ date ┆ bool │\n",
"╞════════════════════════════╪════════════╪════════════╪═════╪════════════╪═══════╡\n",
"│ Hollo Word! ┆ 1.0 ┆ true ┆ 11 ┆ 2023-10-29 ┆ true │\n",
"│ Thank you! ┆ 2.5 ┆ false ┆ 2 ┆ null ┆ false │\n",
"│ Blazingly fast DataFrame!! ┆ 5.0 ┆ true ┆ 333 ┆ 2001-07-05 ┆ null │\n",
"└────────────────────────────┴────────────┴────────────┴─────┴────────────┴───────┘\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"display(df)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 192
},
"outputId": "9cf38960-6fd4-42fa-db0b-914ee7a40289",
"id": "gKXaf4VV_ZIO"
},
"execution_count": 6,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"shape: (3, 6)\n",
"┌────────────────────────────┬────────────┬────────────┬─────┬────────────┬───────┐\n",
"│ long_words ┆ column_abc ┆ column_xyz ┆ abc ┆ mno ┆ xyz │\n",
"│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
"│ str ┆ f64 ┆ bool ┆ i64 ┆ date ┆ bool │\n",
"╞════════════════════════════╪════════════╪════════════╪═════╪════════════╪═══════╡\n",
"│ Hollo Word! ┆ 1.0 ┆ true ┆ 11 ┆ 2023-10-29 ┆ true │\n",
"│ Thank you! ┆ 2.5 ┆ false ┆ 2 ┆ null ┆ false │\n",
"│ Blazingly fast DataFrame!! ┆ 5.0 ┆ true ┆ 333 ┆ 2001-07-05 ┆ null │\n",
"└────────────────────────────┴────────────┴────────────┴─────┴────────────┴───────┘"
],
"text/html": [
"<div><style>\n",
".dataframe > thead > tr,\n",
".dataframe > tbody > tr {\n",
" text-align: right;\n",
" white-space: pre-wrap;\n",
"}\n",
"</style>\n",
"<small>shape: (3, 6)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>long_words</th><th>column_abc</th><th>column_xyz</th><th>abc</th><th>mno</th><th>xyz</th></tr><tr><td>str</td><td>f64</td><td>bool</td><td>i64</td><td>date</td><td>bool</td></tr></thead><tbody><tr><td>&quot;Hollo Word!&quot;</td><td>1.0</td><td>true</td><td>11</td><td>2023-10-29</td><td>true</td></tr><tr><td>&quot;Thank you!&quot;</td><td>2.5</td><td>false</td><td>2</td><td>null</td><td>false</td></tr><tr><td>&quot;Blazingly fast DataFrame!!&quot;</td><td>5.0</td><td>true</td><td>333</td><td>2001-07-05</td><td>null</td></tr></tbody></table></div>"
]
},
"metadata": {}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment