Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move my pandas dataframe to d3?

I am new to Python and have worked my way through a few books on it. Everything is great, except visualizations. I really dislike matplotlib and Bokeh requires too heavy of a stack.

The workflow I want is:

Data munging analysis using pandas in ipython notebook -> visualization using d3 in sublimetext2

However, being new to both Python and d3, I don't know the best way to export my pandas dataframe to d3. Should I just have it as a csv? JSON? Or is there a more direct way?

Side question: Is there any (reasonable) way to do everything in an ipython notebook instead of switching to sublimetext?

Any help would be appreciated.

like image 461
Anton Avatar asked May 14 '14 15:05

Anton


2 Answers

Basically there is no best format what will fit all your visualization needs.

It really depends on the visualizations you want to obtain.

For example, a Stacked Bar Chart takes as input a CSV file, and an adjacency matrix vizualisation takes a JSON format.

From my experience:

  • to display relations beetween items, like adjacency matrix or chord diagram, one will prefer a JSON format that will allow to describe only existing relations. Data are stored like in a sparse matrix, and several data can be nested using dictionary. Moreover this format can directly be parsed in Python.
  • to display properties of an array of items, a CSV format can be fine. A perfect example can be found here with a parallel chart display.
  • to display hierarchical data, like a tree, JSON is best suited.

The best thing to do to help you figure out what best format you need, is to have a look at this d3js gallery

like image 64
Guillaume Jacquenot Avatar answered Sep 29 '22 11:09

Guillaume Jacquenot


You can use D3 directly inside of Jupyter / Ipython. Try the two links below ..

http://blog.thedataincubator.com/2015/08/embedding-d3-in-an-ipython-notebook/

https://github.com/cmoscardi/embedded_d3_example/blob/master/Embedded_D3.ipynb

like image 38
ashishsingal Avatar answered Sep 29 '22 11:09

ashishsingal