首页 > 解决方案 > 语法错误循环(TypeError:'DataFrame' 对象不可调用)

问题描述

如何解决问题?我有一个关于 python 的作业,我想在 csv 中循环数据,这是我的代码

import pandas as p
import numpy as np

df = p.read_csv("mlp.csv")
dataInp = df.drop(["output"],axis=1)
dataOup = df["output"]

v1 = 1.718946
v2 = -1.263178
v3 = -1.083092
w1 = -0.541180 
w2 = 0.54360

i=0
j=0
for i in dataInp:
    for j in dataInp:
        z_in = (dataInp(i,j)*v1)
print(z_in)

和错误输出:

Traceback (most recent call last):
  File "user\a.py", line 22, in <module>
    z_in = (dataInp(i,j)*v1)
TypeError: 'DataFrame' object is not callable

标签: pythonpandas

解决方案


当您应该在行上使用方括号时,您似乎正在使用括号z_in = (dataInp(i,j)*v1)

更正后的代码是z_in = (dataInp[i,j]*v1)

因为您使用的是括号,python 将它解释为好像您试图dataInp作为函数调用一样。


推荐阅读