在 pandas/python 中绘制平行坐标
Plotting parallel coordinates in pandas/python
我正在尝试在 python 中使用 pandas 来绘制以下高维数据:
http://i.stack.imgur.com/34nbR.jpg
这是我的代码:
import pandas
from pandas.tools.plotting import parallel_coordinates
data = pandas.read_csv('ParaCoords.csv')
parallel_coordinates(data,'Name')
代码绘制数据失败,Traceback 错误结束于:
Keyerror: 'Name'
parallel_coordinates 中的第二个参数应该 say/do 是什么?
如何成功绘制数据?
第二个参数应该是定义 class
的列名。想想['dog', 'dog', 'cat', 'bird', 'cat', 'dog']
.
在 example online 中,他们使用 'Name'
作为第二个参数,因为这是一个定义 iris
名称的列
文档
Signature: parallel_coordinates(*args, **kwargs)
Docstring:
Parallel coordinates plotting.
Parameters
----------
frame: DataFrame
class_column: str
Column name containing class names
cols: list, optional
A list of column names to use
ax: matplotlib.axis, optional
matplotlib axis object
color: list or tuple, optional
Colors to use for the different classes
use_columns: bool, optional
If true, columns will be used as xticks
xticks: list or tuple, optional
A list of values to use for xticks
colormap: str or matplotlib colormap, default None
Colormap to use for line colors.
axvlines: bool, optional
If true, vertical lines will be added at each xtick
axvlines_kwds: keywords, optional
Options to be passed to axvline method for vertical lines
kwds: keywords
Options to pass to matplotlib plotting method
您download from UCI没有headers的iris.data文件。要使 pandas 示例工作,您必须将 headers 明确指定为列名:
from pandas.tools.plotting import parallel_coordinates
# The iris.data file from UCI does not have headers,
# so we have to assign the column names explicitly.
data = pd.read_csv("data-iris-for-pandas/iris.data")
data.columns=["x1","x2","x3","x4","Name"]
plt.figure()
parallel_coordinates(data,"Name")
基本上,pandas 文档不完整。有人在不让我们知道的情况下将列名放入数据框中。
我正在尝试在 python 中使用 pandas 来绘制以下高维数据: http://i.stack.imgur.com/34nbR.jpg
这是我的代码:
import pandas
from pandas.tools.plotting import parallel_coordinates
data = pandas.read_csv('ParaCoords.csv')
parallel_coordinates(data,'Name')
代码绘制数据失败,Traceback 错误结束于:
Keyerror: 'Name'
parallel_coordinates 中的第二个参数应该 say/do 是什么? 如何成功绘制数据?
第二个参数应该是定义 class
的列名。想想['dog', 'dog', 'cat', 'bird', 'cat', 'dog']
.
在 example online 中,他们使用 'Name'
作为第二个参数,因为这是一个定义 iris
文档
Signature: parallel_coordinates(*args, **kwargs) Docstring: Parallel coordinates plotting. Parameters ---------- frame: DataFrame class_column: str Column name containing class names cols: list, optional A list of column names to use ax: matplotlib.axis, optional matplotlib axis object color: list or tuple, optional Colors to use for the different classes use_columns: bool, optional If true, columns will be used as xticks xticks: list or tuple, optional A list of values to use for xticks colormap: str or matplotlib colormap, default None Colormap to use for line colors. axvlines: bool, optional If true, vertical lines will be added at each xtick axvlines_kwds: keywords, optional Options to be passed to axvline method for vertical lines kwds: keywords Options to pass to matplotlib plotting method
您download from UCI没有headers的iris.data文件。要使 pandas 示例工作,您必须将 headers 明确指定为列名:
from pandas.tools.plotting import parallel_coordinates
# The iris.data file from UCI does not have headers,
# so we have to assign the column names explicitly.
data = pd.read_csv("data-iris-for-pandas/iris.data")
data.columns=["x1","x2","x3","x4","Name"]
plt.figure()
parallel_coordinates(data,"Name")
基本上,pandas 文档不完整。有人在不让我们知道的情况下将列名放入数据框中。