Coder Social home page Coder Social logo

How to export to dict? about pytablereader HOT 3 CLOSED

thombashi avatar thombashi commented on June 8, 2024
How to export to dict?

from pytablereader.

Comments (3)

thombashi avatar thombashi commented on June 8, 2024

Hi,

The following example can convert a markdown text to a dict:

import json
import pytablereader

t = """
|Borrower|Amount Given|Amount Repaid|Unpaid?|Original Thread|Date Given|
|:--|:--|:--|:--|:--|:--|
|zombievortex|250.00|250.00||[Original Thread](https://www.reddit.com/r/borrow/comments/9wksak/req_250_chicago_il_usa_280_by_124_paypal/)|Nov 13, 2018| 
|zombievortex|150.00|150.00||[Original Thread](https://www.reddit.com/r/borrow/comments/9txiri/req_150_chicago_il_usa_165_by_1110_paypal/)|Nov 3, 2018| 
|zombievortex|60.00|60.00||[Original Thread](https://www.reddit.com/r/borrow/comments/9rslh7/req_60_chicago_il_usa_70_by_112_paypal_prearranged/)|Oct 27, 2018| 
|zombievortex|20.00|20.00||[Original Thread](https://www.reddit.com/r/borrow/comments/9pq90e/req_20_chicago_il_usa_2250_by_1026_paypal_venmo/)|Oct 20, 2018|
"""

p = pytablereader.MarkdownTableTextLoader(t)
for i in p.load():
    # you can get dict by as_dict method
    print(json.dumps(i.as_dict(), indent=4))
{
    "markdown1": [
        {
            "Borrower": "zombievortex",
            "Amount Given": 250,
            "Amount Repaid": 250,
            "Unpaid?": "",
            "Original Thread": "Original Thread",
            "Date Given": "Nov 13, 2018"
        },
        {
            "Borrower": "zombievortex",
            "Amount Given": 150,
            "Amount Repaid": 150,
            "Unpaid?": "",
            "Original Thread": "Original Thread",
            "Date Given": "Nov 3, 2018"
        },
        {
            "Borrower": "zombievortex",
            "Amount Given": 60,
            "Amount Repaid": 60,
            "Unpaid?": "",
            "Original Thread": "Original Thread",
            "Date Given": "Oct 27, 2018"
        },
        {
            "Borrower": "zombievortex",
            "Amount Given": 20,
            "Amount Repaid": 20,
            "Unpaid?": "",
            "Original Thread": "Original Thread",
            "Date Given": "Oct 20, 2018"
        }
    ]
}

MarkdownTableTextLoader class expected to pass a whole markdown text (i.e. cannot parse lines of markdown).

from pytablereader.

sometimescool22 avatar sometimescool22 commented on June 8, 2024

Thanks, works. 👍

from pytablereader.

sometimescool22 avatar sometimescool22 commented on June 8, 2024

For anyone referring to this issue, I had to add this to thombashi's code:

json_object = json.loads(j)

from pytablereader.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.