Please bear with me as I am quite new to python:
Currently here is my code:
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()
The output is below:
/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
I am unsure of how to resolve the numpy.float.64. I am trying to create graphs of list which are numbers that are sorted from data. The code should print 7 graphs in total. If sharing the can data file would help please leave a comment.
AttributeError, forobj.attr, then eitherobjis not what you think should be, or you misread the docs forobjand are asking for the wrong attribute (or method). Most often it's the former. Here yourlist[i]is an element of a numpy array, which does not havetimesormagsattributes (whatever those are supposed to be).