简体   繁体   English

Python 代码无法运行,我不知道如何修复它

[英]Python code doesn't run, I don't know what to do to fix it

class AQGraph:
    import pandas as pd
    import numpy as np
    import matplotlib as plt

    PrimaryA = pd.read_csv('PrimaryA.csv')  # Daily data from 12/1/19 to 4/16/20 from PrimaryA sensor
    PrimaryB = pd.read_csv('PrimaryB.csv')  # Daily data from 12/1/19 to 4/16/20 from PrimaryB sensor
    AverageData = np.mean(PrimaryA[:][2], PrimaryB[:][2])

    print(AverageData)
    plt.plot(PrimaryA[:][0], AverageData)
    plt.show()

Attached is my python code.附上我的 python 代码。 I'm running it in Pycharm and for some reason the green arrow that pops up for Pycharm files isn't there.我在 Pycharm 中运行它,由于某种原因,为 Pycharm 文件弹出的绿色箭头不存在。 I've looked through my settings and I'm running Python 3.7.我查看了我的设置,我正在运行 Python 3.7。 Any advice?有什么建议吗?

The code you provided, doesn't comply with python rules and standards.您提供的代码不符合 python 规则和标准。 there is a class in your code without any constructor or any method.您的代码中有一个class没有任何构造函数或任何方法。 Also, you didn't follow Python's indentation policy.此外,您没有遵循 Python 的缩进策略。 Based on what you provided, as soon as you try to run it you should see an error.根据您提供的内容,一旦您尝试运行它,您应该会看到一个错误。

import pandas as pd
import numpy as np
import matplotlib as plt
class AQGraph:

    @staticmethod
    def a_method():

        PrimaryA = pd.read_csv('PrimaryA.csv')  # Daily data from 12/1/19 to 4/16/20 from PrimaryA sensor
        PrimaryB = pd.read_csv('PrimaryB.csv')  # Daily data from 12/1/19 to 4/16/20 from PrimaryB sensor
        AverageData = np.mean(PrimaryA[:][2], PrimaryB[:][2])

        print(AverageData)
        plt.plot(PrimaryA[:][0], AverageData)
        plt.show()


if __name__ == "__main__":
    AQGraph.a_method()

In the command line try:在命令行中尝试:

> python python_file.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM