pandas 如何将我的熊猫数据框移动到 d3?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23659234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to move my pandas dataframe to d3?
提问by Anton
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.
我是 Python 的新手,并且已经阅读了一些关于它的书籍。一切都很棒,除了可视化。我真的不喜欢 matplotlib 和 Bokeh 需要太多的堆栈。
The workflow I want is:
我想要的工作流程是:
Data munging analysis using pandas in ipython notebook -> visualization using d3 in sublimetext2
在 ipython notebook 中使用 pandas 进行数据处理分析 -> 在 sublimetext2 中使用 d3 进行可视化
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?
但是,作为 Python 和 d3 的新手,我不知道将 Pandas 数据帧导出到 d3 的最佳方法。我应该把它作为一个csv吗?JSON?或者有更直接的方法吗?
Side question: Is there any (reasonable) way to do everything in an ipython notebook instead of switching to sublimetext?
附带问题:是否有任何(合理的)方法可以在 ipython 笔记本中完成所有操作而不是切换到 sublimetext?
Any help would be appreciated.
任何帮助,将不胜感激。
回答by Guillaume Jacquenot
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 Charttakes as input a CSV file, and an adjacency matrix vizualisationtakes a JSON format.
例如,堆叠条形图将 CSV 文件作为输入,邻接矩阵可视化采用 JSON 格式。
From my experience:
根据我的经验:
- to display relations beetween items, like adjacency matrixor 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 herewith a parallel chart display.
- to display hierarchical data, like a tree, JSON is best suited.
- 要显示项目之间的关系,如邻接矩阵或和弦图,人们会更喜欢一种 JSON 格式,它只允许描述现有的关系。数据像稀疏矩阵一样存储,并且可以使用字典嵌套多个数据。而且这种格式可以直接在 Python 中解析。
- 要显示一组项目的属性,CSV 格式就可以了。可以在此处找到具有并行图表显示的完美示例。
- 要显示分层数据,如树,JSON 最适合。
The best thing to do to help you figure out what best format you need, is to have a look at this d3js gallery
帮助您确定所需的最佳格式的最佳方法是查看此 d3js 图库
回答by ashishsingal
You can use D3 directly inside of Jupyter / Ipython. Try the two links below ..
您可以直接在 Jupyter / Ipython 内部使用 D3。试试下面的两个链接..
http://blog.thedataincubator.com/2015/08/embedding-d3-in-an-ipython-notebook/
http://blog.thedataincubator.com/2015/08/embedding-d3-in-an-ipython-notebook/
https://github.com/cmoscardi/embedded_d3_example/blob/master/Embedded_D3.ipynb
https://github.com/cmoscardi/embedded_d3_example/blob/master/Embedded_D3.ipynb

