如何创建切片的CSV文件的散点图矩阵?

我是python和Pandas的新手。我正在尝试将机器学习作为一种业余爱好比什么都重要。到目前为止,这就是我所拥有的。

我不知道如何停止代码并放入我得到的错误。

使用此代码,我不断收到此错误。我该如何解决?

  File "college.py", line 12, in <module>
    pd.plotting.scatter_matrix(data1) 
  File "/Users//Library/Python/3.7/lib/python/site-packages/pandas/plotting/_misc.py", line 134, in scatter_matrix
    **kwargs,
  File "/Users//Library/Python/3.7/lib/python/site-packages/pandas/plotting/_matplotlib/misc.py", line 30, in scatter_matrix
    fig, axes = _subplots(naxes=naxes, figsize=figsize, ax=ax, squeeze=False)
  File "/Users//Library/Python/3.7/lib/python/site-packages/pandas/plotting/_matplotlib/tools.py", line 231, in _subplots
    ax0 = fig.add_subplot(nrows, ncols, 1, **subplot_kw)
  File "/Users//Library/Python/3.7/lib/python/site-packages/matplotlib/figure.py", line 1414, in add_subplot
    a = subplot_class_factory(projection_class)(self, *args, **kwargs)
  File "/Users//Library/Python/3.7/lib/python/site-packages/matplotlib/axes/_subplots.py", line 59, in __init__
    f"num must be 1 <= num <= {rows*cols}, not {num}")
ValueError: num must be 1 <= num <= 0, not 1
import matplotlib.pyplot as plt 
import pandas as pd 

data = pd.read_csv('college.csv', index_col = 0) 

# Summarize Dataset
print(data.describe())

# Plot first 10 columns into scatterplot matrix 
data1 = data.iloc[0:10]
pd.plotting.scatter_matrix(data1)```
评论
自大狂
自大狂

您可以在pandas plot函数中使用kind参数

data1.plot(kind='scatter',x='x_var',y='y_var')
点赞
评论