Skip to main content

a simpler tool for convert markdown table to polars

Project description

mdpolars_py

a simple tool for convert markdown table to polars in python3. This tool is a lightweight tool for testing a code, so note that we are not validating the user's input.

pandas version is here

install

pip install mdpolars

usage

import polars as pl
import mdpolars

df = mdpolars.from_md("""
+------------+-------+
| id         | score |
+------------+-------+
| 1          | 15    |
| 2          | 11    |
| 3          | 11    |
| 4          | 20    |
+------------+-------+
""", schema=[("id", pl.Int64), ("score", pl.Int64)])

print(df)
# shape: (4, 2)
# ┌─────┬───────┐
# │ id  ┆ score │
# │ --- ┆ ---   │
# │ i64 ┆ i64   │
# ╞═════╪═══════╡
# │ 1   ┆ 15    │
# │ 2   ┆ 11    │
# │ 3   ┆ 11    │
# │ 4   ┆ 20    │
# └─────┴───────┘
# the header can be overwritten if the header exists
import mdpolars
df = mdpolars.from_md("""
+------------+-------+
| id         | score |
+------------+-------+
| 1          | 15    |
| 2          | 11    |
| 3          | 11    |
| 4          | 20    |
+------------+-------+
""", schema=["foo", "bar"])

# the default type is str.
print(df)
# shape: (4, 2)
# ┌─────┬─────┐
# │ foo ┆ bar │
# │ --- ┆ --- │
# │ str ┆ str │
# ╞═════╪═════╡
# │ 1   ┆ 15  │
# │ 2   ┆ 11  │
# │ 3   ┆ 11  │
# │ 4   ┆ 20  │
# └─────┴─────┘

accepted table patterns

| Syntax    | Description |
| --------- | ----------- |
| Header    | Title       |
| Paragraph | Text        |
+------------+-------------+
| Syntax     | Description |
+------------+-------------+
| Header     | Title       |
| Paragraph  | Text        |
+------------+-------------+
| Syntax    | Description |
| :-------- | ----------: |
| Header    | Title       |
| Paragraph | Text        |
| Header    | Title       |
| Paragraph | Text        |

contribute

If you have suggestions for features or improvements to the code, please feel free to create an issue or PR.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdpolars-0.1.0.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

mdpolars-0.1.0-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page