Python 如何修复AttributeError:';numpy.float64';对象没有属性';泰晤士报';在这个代码中?

Python 如何修复AttributeError:';numpy.float64';对象没有属性';泰晤士报';在这个代码中?,python,pandas,numpy,Python,Pandas,Numpy,请容忍我,因为我对python还很陌生: 目前我的代码如下: import pandas as pd import statistics import matplotlib.pyplot as plt import math df = pd.read_csv(r"/Users/aaronhuang/Documents/Desktop/ffp/exfileCLEAN2.csv", skiprows=[1]) # replace this w

请容忍我,因为我对python还很陌生:

目前我的代码如下:

import pandas as pd
import statistics
import matplotlib.pyplot as plt
import math

df = pd.read_csv(r"/Users/aaronhuang/Documents/Desktop/ffp/exfileCLEAN2.csv",
                 skiprows=[1])  # replace this with wherever the  file is.

magnitudes = df['Magnitude '].values
times = df['Time '].values
average = statistics.mean(magnitudes)
sd = statistics.stdev(magnitudes)
below = sd * 3


class data_set:
    def __init__(self, index):
        self.mags = []
        self.i = index
        self.times = []
        for ii in range(20):
            self.times.append(df['Time '][i + ii - 10])
            self.mags.append(df['Magnitude '][i + ii - 10])
        (self.mags)


data = []
list = []
i = 0
while (i < len(df['Magnitude '])):
    if (abs(df['Magnitude '][i]) <= (average - below)):
        print(df['Time '][i])
        list.append(df['Time '][i])
        data.append(data_set(i))


    i += 1

print("found values")

first_range = 0
for n in list:
    if n - first_range <= 10:
        pass
    else:
        print(n)
        first_range = n






# graphing

height = 8  # Change this for number of columns
width = math.ceil(len(list) / height)  # Change this to change the number of ROWS
fig, axes = plt.subplots(width, height, figsize=(30, 30))

row = 0
col = 0

for i in range(len(list)):
    axes[row][col].plot(list[i].times, list[i].mags)
    # axes[0][i].set_xticklabels(df['Time '], rotation=45)
    col += 1
    if (col > height - 1):
        col = 0
        row += 1

plt.show()
将熊猫作为pd导入
进口统计
将matplotlib.pyplot作为plt导入
输入数学
df=pd.read_csv(r)/Users/aaronhuang/Documents/Desktop/ffp/exfileCLEAN2.csv“,
skiprows=[1])#将其替换为文件所在的位置。
震级=df[‘震级’]。数值
时间=df['Time']。值
平均值=统计值。平均值(震级)
sd=统计数据。标准偏差(震级)
低于=sd*3
类数据集:
定义初始化(自,索引):
self.mags=[]
self.i=索引
self.times=[]
对于范围(20)内的ii:
self.times.append(df['Time'][i+ii-10])
自磁附加(df['magnity'][i+ii-10])
(self.mags)
数据=[]
列表=[]
i=0
而(i如果(abs(df['magnity'][i])您的变量
list
正在从
list.append(df['Time'][i])
获取单个浮点值,则需要将
数据集
对象放在其中


此外,尽管它是合法的Python,但通常情况下,将变量命名为与内置变量相同是一种不好的做法,因为您使用了
list
,此后您将很难创建一个类型为
list

的新对象,这是否意味着我应该在不访问数据集的情况下,将所有
列表
替换为
数据集
很难说你正在处理的问题或者你对你要解决的问题有强烈的感觉。我怀疑你所做的有点过于复杂,可能只是数据帧上的一些
pandas
操作,但我不能确定你有
AttributeError
,对于
obj.attr
,然后是ei
obj
不是您认为应该是的,或者您误读了文档中的
obj
,并要求错误的属性(或方法)。通常是前者。这里您的
列表[i]
是numpy数组的一个元素,它没有
times
mag
属性(无论这些属性是什么).
/Users/aaronhuang/.conda/envs/EXTTEst/bin/python "/Users/aaronhuang/PycharmProjects/EXTTEst/Code sandbox.py"
2456116.494
2456116.535
2456116.576
2456116.624
2456116.673
2456116.714
2456116.799
2456123.527
2456166.634
2456570.526
2456595.515
2457485.722
2457497.93
2457500.674
2457566.874
2457567.877
found values
2456116.494
2456166.634
2456570.526
2456595.515
2457485.722
2457497.93
2457566.874
Traceback (most recent call last):
  File "/Users/aaronhuang/PycharmProjects/EXTTEst/Code sandbox.py", line 65, in <module>
    axes[row][col].plot(list[i].times, list[i].mags)
AttributeError: 'numpy.float64' object has no attribute 'times'

Process finished with exit code 1