python - SyntaxError:循环块之后的语法无效

时间:2018-06-16 10:00:31

标签: python pandas pyqt5

我正在尝试使用QTableView对象在PyQt中创建一个表。我的数据存储在Pandas数据框中。

以下是代码:

from PyQt5 import QtCore, QtGui, QtWidgets
import pandas as pd

cust_data = pd.read_csv('C:\\Users\\utkarsh.a.ranjan\\Documents\\final_datasets\\minimal_data.csv')

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(524, 424)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.tableView = QtWidgets.QTableView(self.centralwidget)
        self.tableView.setGeometry(QtCore.QRect(60, 20, 411, 351))
        self.tableView.setMouseTracking(False)
        self.tableView.setObjectName("custData")
        self.tableView.setRowCount(cust_data.head().shape[0])
        self.tableView.setColumnCount(cust_data.head().shape[1])
        for i in range(cust_data.head().shape[0]):
            for j in range(cust_data.head().shape[0]):
                self.tableWidget.setItem(i,j, QTableWidgetItem(cust_data.iloc[i, j])
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 524, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))


if __name__ == "__main__":
    import sys
    if not QtWidgets.QApplication.instance():
        app = QtWidgets.QApplication(sys.argv)
    else:
        app = QtWidgets.QApplication.instance()
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

我在for循环之后的行中遇到语法错误。我没有发现任何语法问题。如果我删除嵌套的for循环,则错误消失。我在spyder IDE上运行代码

1 个答案:

答案 0 :(得分:0)

您在<?php error_reporting(E_ALL); ini_set('display_errors', 1); function searchmembers($search_term){ global $con; $sql = mysqli_query($con, "SELECT * FROM `artist` WHERE `Band` LIKE '%$search_term%' OR `Genre` LIKE '%$search_term%' LIMIT 0, 30 ") or die (mysqli_error()); $num_of_row = mysqli_num_rows($sql); if ($num_of_row > 0 ){ $i=0; echo"<table>"; while($row = mysqli_fetch_array($sql)) { $id = $row['Band']; $Pic = $row['Pic']; $i++; ?> <?php if($i%3==1){ ?> <tr> <?php }?> <td><img src="<?php echo $row['Pic']; ?>" height="100" width="100" align="middle" /></td> <?php echo "<td><a href ='profile.php?Band=$id' style='color:white; text-decoration:none;'>". $row['Band'].""; <?php if($i%3==1){ ?> </tr> <?php }?> } echo"</table>"; } else { echo "<font color='red' size='4' >No result found!</font>"; }

末尾缺少右括号