如何在python spyder上使用csv文件查找平均数而无需选择

lokaqttq  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(360)

关闭。这个问题需要详细或明确。它目前不接受答案。
**想改进这个问题吗?**编辑这篇文章,添加细节并澄清问题。

昨天关门了。
改进这个问题
嗨,我是python编程的新成员,我目前正在使用csv文件编码到spyder中,我被困在这里
代码如下:

loop = True
totalNumberofvistitors = 0

while loop: #loop to select the museum
    print("\nPlease select an option from below")

    for x in range (1,7): #refer to function1, same method
        print(x, ":" , museumvisitors_data[x][0])

    selection1 = int(input("Selection: "))

    if selection1 >= 1 and selection1 <= 8:
        while loop: 
                loop = False                    
                for x in range (1,7):
                    totalNumberofvistitors += int(museumvisitors_data[selection1][x]) #sum up the values in the list

                print(museumvisitors_data[selection1][0], totalNumberofvistitors/7) #divide total by 7 to find mean
    else:
        print("\nInvalid selection, please try another")

目前,它现在可以工作,但我不想与选择工作。提前谢谢!

hmmo2u0o

hmmo2u0o1#

也许你可以使用Pandas图书馆来解决这个问题。请安装 pandas 使用以下代码段的库 pip install pandas ```

Read the file

df = pd.read_csv(r'filename.csv')

Describe the data

df.describe()

相关问题