PolyMathOrg / DataFrame

DataFrame in Pharo - tabular data structures for data analysis
MIT License
74 stars 29 forks source link

Added DataFrame>> #toMarkdown along with tests #246

Closed Joshua-Dias-Barreto closed 1 year ago

Joshua-Dias-Barreto commented 1 year ago

I've implemented a method toMarkdown so that DataFrames can be converted to a Markdown formatted table.

    df := DataFrame withRows:
              #( #( 'Barcelona' 1.609 true ) 
                         #( 'Dubai' 2.789 true )
                 #( 'London' 8.788 false ) ).

    df rowNames: #( 'A' 'B' 'C' ).
    df columnNames: #( 'City' 'Population' 'BeenThere' ).

df toMarkdown.

This should return a string which can be copy-pasted in an editor which supports Markdown.

| #   | City        | Population | BeenThere | 
| --- | ----------- | ---------- | --------- | 
| 'A' | 'Barcelona' | 1.609      | true      | 
| 'B' | 'Dubai'     | 2.789      | true      | 
| 'C' | 'London'    | 8.788      | false     | 
It would look like this once this text is pasted in a Markdown supported editor : # City Population BeenThere
'A' 'Barcelona' 1.609 true
'B' 'Dubai' 2.789 true
'C' 'London' 8.788 false