textual-pandas
A module to display Pandas DataFrames in Textual's DataTable widget.
Background
Pandas is a popular Python library for data analysis. One of the core components of Pandas is the DataFrame object. A DataFrame is a two-dimensional data structure that represents data in rows and columns.
Given Pandas DataFrames are tabular in nature, it makes sense to be able to render them in Textual using the DataTable widget. Enter the DataFrameTable widget...
Installation
Install textual-pandas via pip:
pip install textual-pandas
Getting Started
textual-pandas introduces a new widget called DataFrameTable, which uses Textual's DataTable widget as a base.
First, you'll need to import the DataFrameTable widget.
from textual_pandas.widgets import DataFrameTable
After importing the widget, you'll need to yield the DataFrameTable widget in your Textual app's compose() method (like you would with the DataTable widget). Once you're ready to draw the table with your DataFrame data (most likely on_mount()), you'll simply call the add_df() method and pass in a Pandas DataFrame.
from textual.app import App
from textual_pandas.widgets import DataFrameTable
import pandas as pd
# Pandas DataFrame
df = pd.DataFrame()
df["Name"] = ["Dan", "Ben", "Don", "John", "Jim", "Harry"]
df["Score"] = [77, 56, 90, 99, 83, 69]
df["Grade"] = ["C", "F", "A", "A", "B", "D"]
class ClassApp(App):
def compose(self):
yield DataFrameTable()
def on_mount(self):
table = self.query_one(DataFrameTable)
table.add_df(df)
That's it! Now your DataFrame will display within a DataTable widget!
Updating the DataFrame
If you update your DataFrame, and would like to see the updates in your app, then you'll need to use the update_df() method and pass in your updated DataFrame object.
If you only want to update the rendered DataFrameTable (without the need to change the DataFrame), you may also use the update_cell() and update_cell_at() methods that are provided by the DataTable widget.
df.insert(
1,
"Teacher",
[
"Mr. Smith",
"Mr. Smith",
"Mr. Smith",
"Mr. Smith",
"Mr. Smith",
"Mr. Smith",
],
)
table = self.query_one(DataFrameTable)
# Provide new DataFrame to update DataFrameTable widget
table.update_df(df)
Contributing
I built this module for the sole purpose of displaying a Pandas DataFrame in a DataTable widget. I'm sure there's additional functionality with the Pandas library that others would like to see!
If you have any ideas, questions, or issues, please feel free to open an issue or PR!
Metadata
Release files for textual-pandas 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| textual_pandas-0.2.3.tar.gz | 3.0 kB | Without provenance | Details for textual_pandas-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| textual_pandas-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for textual_pandas-0.2.3-py3-none-any.whl |
Total release size: 6.8 kB
Release files / textual_pandas-0.2.3.tar.gz
| Download URL | textual_pandas-0.2.3.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b18ce7590f545b891c693e5cabf3ccdcb232725ce081eb7a482373ab3218707
|
|
BLAKE2b-256 checksum How to use checksums |
61c4a975021d1c74b156726b9951943d08992a22db56dfc37923e5385b9388da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.9.13 Darwin/23.2.0
|
Release files / textual_pandas-0.2.3-py3-none-any.whl
| Download URL | textual_pandas-0.2.3-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
539583e6f1a8c3ee51e1578f34bd79a0cfc8ef17a5598b0fe8470d3cd2d62c3c
|
|
BLAKE2b-256 checksum How to use checksums |
425eb5868e1acd754474e1a37b73024c65529a269fb88d7c158d3f065c145ef1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.9.13 Darwin/23.2.0
|
Security for textual-pandas 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.