ipy_table icon indicating copy to clipboard operation
ipy_table copied to clipboard

is it possible display several dataframes side by side ?

Open dragosbo opened this issue 7 years ago • 5 comments

Hi

I was wondering if there is a way to use your package to display several data frames side by side in a jupyter notebook cell. kind of being able to replicate the powepoint slides from this youtube video

https://www.youtube.com/watch?v=9d5-Ti6onew

thanks in advance Dragos

dragosbo avatar Oct 09 '17 21:10 dragosbo

Hi Dragos!

I think the best approach is to just write a little function that puts each table into a cell of another (invisible) table. You can get the HTML representation of an IpyTable object by calling its .repr_html() method.

The function multi_table() below accepts a list of tables, calls .repr_html() on each to get their HTML, shoves each one into the cell of a vanilla html table, and renders the resulting blob of html using the HTML() function from IPython.core.display.

You should be able to control the formatting (cell spacing, etc) by modifying the code to add more style properties etc. to the html of the outer table.

Cheers!

from IPython.core.display import HTML

def multi_table(table_list):
    ''' Acceps a list of IpyTable objects and returns a table which contains each IpyTable in a cell
    '''
    return HTML(
        '<table><tr style="background-color:white;">' + 
        ''.join(['<td>' + table._repr_html_() + '</td>' for table in table_list]) +
        '</tr></table>'
    )
mutli_table1 mutli_table2

epmoyer avatar Oct 10 '17 01:10 epmoyer

Hi Eric

Many thanks for the fast response. I will play around with your solution. when I will be happy with the output I will come back to you and share my findings :)

all the best Dragos

On Tue, Oct 10, 2017 at 3:41 AM, Eric Moyer [email protected] wrote:

Hi Dragos!

I think the best approach is to just write a little function that puts each table into a cell of another (invisible) table. You can get the HTML representation of an IpyTable object by calling its .repr_html() method.

The function multi_table() below accepts a list of tables, calls . repr_html() on each to get their HTML, shoves each one into the cell of a vanilla html table, and renders the resulting blob of html using the HTML() function from IPython.core.display.

You should be able to control the formatting (cell spacing, etc) by modifying the code to add more style properties etc. to the html of the outer table.

Cheers!

from IPython.core.display import HTML def multi_table(table_list): ''' Acceps a list of IpyTable objects and returns a table which contains each IpyTable in a cell ''' return HTML( '

' + ''.join(['' for table in table_list]) + '
' + table.repr_html() + '
' )

[image: mutli_table1] https://user-images.githubusercontent.com/136718/31365413-c0734bc0-ad1f-11e7-89b7-237a747742f7.png

[image: mutli_table2] https://user-images.githubusercontent.com/136718/31365417-c2faddfe-ad1f-11e7-9eff-fb24756afce9.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/epmoyer/ipy_table/issues/24#issuecomment-335334742, or mute the thread https://github.com/notifications/unsubscribe-auth/AfJDwd2OyWdm2pT1X8UwKZeNDu0nHIthks5sqstIgaJpZM4PzGks .

dragosbo avatar Oct 10 '17 18:10 dragosbo

I am trying to use this solution but there is no module named add_parent_to_path.

Is this is a custom module that the author implemented? A wide search in google finds no modules by that name.

richlysakowski avatar Jul 03 '19 18:07 richlysakowski

This is great. I just used it on my dataframes.

Thanks

theAfricanQuant avatar Jun 20 '20 16:06 theAfricanQuant

Thank you for your function. Works great!

denmanorwat avatar May 09 '21 09:05 denmanorwat