3

我正在尝试在 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 中的第二个参数应该说/做什么?如何成功绘制数据?

4

2 回答 2

1

第二个参数应该是定义的列名class。想想['dog', 'dog', 'cat', 'bird', 'cat', 'dog']

在线示例中,它们'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
于 2016-06-29T15:35:49.897 回答
0

您从 UCI 下载的 iris.data 文件没有标题。要使 pandas 示例正常工作,您必须将标题明确指定为列名:

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 平行坐标示例

基本上,熊猫文档是不完整的。有人在不让我们知道的情况下将列名放入数据框中。

于 2017-09-08T19:14:59.037 回答