TypeError:“模块”对象不可调用-无法显示我的训练数据集散点图

时间:2019-03-26 04:03:34

标签: python numpy scipy

我有一个200列和650行的数据集,我想绘制一个散点图,但显示“ TypeError:'模块'对象不可调用”

在尝试输入所有列名的培训时,我读取了具有工作表名称的excel工作表

# The snippet below will load the Thurstone Interest Schedule dataset and create a scatter plot matrix of the dataset.
# Scatter Plot Matrix
import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import scatter_matrix
df = pd.read_excel (r'F:\Thurstone Project\Training Dataset.xlsx', sheet_name='Training')
names = ['Physicist', 'Mechanical Engineer', 'Inventor', 'Chemist', 'Electrical Engineer',.........]
data = pd(df, names=names)
scatter_matrix(data)
plt.show();

运行上面的代码时出现以下错误

TypeError                                 Traceback (most recent call last)
<ipython-input-2-c204cb64f383> in <module>
      6 df = pd.read_excel (r'F:\Thurstone Project\Training Dataset.xlsx', sheet_name='Training')
      7 names = ['Physicist', 'Mechanical Engineer', 'Inventor', 'Chemist', ...... ]
----> 8 data = pd(df, names=names)
      9 scatter_matrix(data)
     10 plt.show();

TypeError: 'module' object is not callable

我希望输出为散点图...

1 个答案:

答案 0 :(得分:0)

发现错误。您将pandas库导入为pd,然后在代码中使用pd(df, names=names),这是无效的用法。在我看来,您正在尝试创建一个数据框并使用pd(df, names=names)向列提供名称。正确的呼叫应为pd.DataFrame(data, columns=names)

但是,实际上这是不必要的,因为您已经从df = pd.read_excel (r'F:\Thurstone Project\Training Dataset.xlsx', sheet_name='Training')中获得了一个数据框。此后,您可以通过调用以下行将名称应用于列:

df.columns = ['Physicist', 'Mechanical Engineer', 'Inventor', 'Chemist', 'Electrical Engineer',.........]