Skip to content

Added DataFrame>> #toMarkdown along with tests#246

Merged
jecisc merged 2 commits intoPolyMathOrg:masterfrom
Joshua-Dias-Barreto:markdownPrinter
Jun 1, 2023
Merged

Added DataFrame>> #toMarkdown along with tests#246
jecisc merged 2 commits intoPolyMathOrg:masterfrom
Joshua-Dias-Barreto:markdownPrinter

Conversation

@Joshua-Dias-Barreto
Copy link
Copy Markdown
Collaborator

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

Comment thread src/DataFrame/DataFrame.class.st Outdated
" Prints the DataFrame as a Markdown formatted table"

| markdown columnWidths |
self addColumn: self rowNames named: '#' atPosition: 1.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we act on the receiver? Shouldn't we copy the dataframe? Because here I have the impression that calling this method will change the original data frame and I don't think this is what we want.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right, I made the changes.

@jecisc jecisc merged commit 67e2515 into PolyMathOrg:master Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants