May-23-2019, 07:24 PM
This is the list I am working with:
2015-01-25 14:05:41.274647 70
2015-01-25 14:08:05.036915 2070
2015-01-25 14:10:05.536604 70
2015-01-25 14:12:05.142511 2070
2015-01-25 14:14:05.045367 70
2015-01-25 14:16:05.005320 70
2015-01-25 14:18:06.639303 70
2015-01-25 14:20:04.753845 70
the third line of the third column is supposed to be an error, and my code should make it equal to the average
between the value before and after. In short I should be replacing that 70 with 2070.
My code keeps printing 70.
Not sure why.
I have tried to change the code:
2015-01-25 14:05:41.274647 70
2015-01-25 14:08:05.036915 2070
2015-01-25 14:10:05.536604 70
2015-01-25 14:12:05.142511 2070
2015-01-25 14:14:05.045367 70
2015-01-25 14:16:05.005320 70
2015-01-25 14:18:06.639303 70
2015-01-25 14:20:04.753845 70
the third line of the third column is supposed to be an error, and my code should make it equal to the average
between the value before and after. In short I should be replacing that 70 with 2070.
My code keeps printing 70.
Not sure why.
from astral import Astral from scipy import * from pylab import* import numpy as np from numpy import array import matplotlib.pyplot as plt import datetime from datetime import timezone from datetime import timedelta import matplotlib.dates as dates import pandas as pd import pytz import sys def last_digits(num, last_digits_count=2): return abs(num) % (10**last_digits_count) orig_date=[] orig_time=[] movements=[] with open('bird_jan25jan16.txt', 'r') as f: for line in f: data = line.split() # Splits on whitespace orig_date.append(data[0][:]) orig_time.append(data[1][:]) movements.append(int(data[2][:])) for i in range(len(orig_date)): if (len(str(movements[i])) >= 3 ): if movements[i]==0 or ( movements[i-1] == movements[i+1] !=movements[i] and (last_digits(movements[i]) == last_digits(movements[i+1]))): movements[i]=(movements[i-1]+movements[i+1])/2 print(movements[2])
I have tried to change the code:
from astral import Astral from scipy import * from pylab import* import numpy as np from numpy import array import matplotlib.pyplot as plt import datetime from datetime import timezone from datetime import timedelta import matplotlib.dates as dates import pandas as pd import pytz import sys def last_digits(num, last_digits_count=2): return abs(num) % (10**last_digits_count) orig_date=[] orig_time=[] movements=[] with open('bird_jan25jan16.txt', 'r') as f: for line in f: data = line.split() # Splits on whitespace orig_date.append(data[0][:]) orig_time.append(data[1][:]) movements.append(int(data[2][:])) for i in range(len(orig_date)): if movements[i]==0 or ( (movements[i-1] == movements[i+1] !=movements[i]) and ((last_digits(movements[i]) == last_digits(movements[i+1]))) and ((len(str(movements[i-1])) - len(str(movements[1]))) >=2)): movements[i]=(movements[i-1]+movements[i+1])/2 print(movements[2],orig_date[0],orig_time[0])and now I get this error
Error: File "<ipython-input-80-389e619abf53>", line 1, in <module>
runfile('C:/Users/Desktop/python ode/birds_2nd_draft.py', wdir='C:/Users/Desktop/python ode')
File "C:\Users\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
execfile(filename, namespace)
File "C:\Users\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Desktop/python ode/birds_2nd_draft.py", line 36, in <module>
if movements[i]==0 or ( (movements[i-1] == movements[i+1] !=movements[i]) and
IndexError: list index out of range